// RUN: %clang_cc1 -std=c++11 -verify %s typedef int (*fp)(int); int surrogate(int); struct Incomplete; // expected-note{{forward declaration of 'Incomplete'}} \ // expected-note {{forward declaration of 'Incomplete'}} struct X { X() = default; // expected-note{{candidate constructor not viable: requires 0 arguments, but 1 was provided}} X(const X&) = default; // expected-note{{candidate constructor not viable: no known conversion from 'bool' to 'const X' for 1st argument}} X(bool b) __attribute__((enable_if(b, "chosen when 'b' is true"))); // expected-note{{candidate disabled: chosen when 'b' is true}} void f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); void f(int n) __attribute__((enable_if(n == 1, "chosen when 'n' is one"))); // expected-note{{member declaration nearly matches}} expected-note 2{{candidate disabled: chosen when 'n' is one}} void g(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); // expected-note{{candidate disabled: chosen when 'n' is zero}} void h(int n, int m = 0) __attribute__((enable_if(m == 0, "chosen when 'm' is zero"))); // expected-note{{candidate disabled: chosen when 'm' is zero}} static void s(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); // expected-note2{{candidate disabled: chosen when 'n' is zero}} void conflict(int n) __attribute__((enable_if(n+n == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}} void conflict(int n) __attribute__((enable_if(n*2 == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}} void hidden_by_argument_conversion(Incomplete n, int m = 0) __attribute__((enable_if(m == 10, "chosen when 'm' is ten"))); Incomplete hidden_by_incomplete_return_value(int n = 0) __attribute__((enable_if(n == 10, "chosen when 'n' is ten"))); // expected-note{{'hidden_by_incomplete_return_value' declared here}} operator long() __attribute__((enable_if(true, "chosen on your platform"))); operator int() __attribute__((enable_if(false, "chosen on other platform"))); operator fp() __attribute__((enable_if(false, "never enabled"))) { return surrogate; } // expected-note{{conversion candidate of type 'int (*)(int)'}} // FIXME: the message is not displayed
// RUN: %clang_cc1 %s -verify // RUN: %clang_cc1 %s -DCODEGEN -emit-llvm -o - | FileCheck %s #define O_CREAT 0x100 typedef int mode_t; typedef unsigned long size_t; const int TRUE = 1; int open(const char *pathname, int flags) __attribute__((enable_if(!(flags & O_CREAT), "must specify mode when using O_CREAT"))) __attribute__((overloadable)); // expected-note{{candidate disabled: must specify mode when using O_CREAT}} int open(const char *pathname, int flags, mode_t mode) __attribute__((overloadable)); // expected-note{{candidate function not viable: requires 3 arguments, but 2 were provided}} void test1() { #ifndef CODEGEN open("path", O_CREAT); // expected-error{{no matching function for call to 'open'}} #endif open("path", O_CREAT, 0660); open("path", 0); open("path", 0, 0); } size_t __strnlen_chk(const char *s, size_t requested_amount, size_t s_len); size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function}} __attribute__((overloadable)) __asm__("strnlen_real1"); __attribute__((always_inline)) inline size_t strnlen(const char *s, size_t maxlen) // expected-note{{candidate function}} __attribute__((overloadable)) __attribute__((enable_if(__builtin_object_size(s, 0) != -1,
struct X { void f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); void f(int n) __attribute__((enable_if(n == 1, "chosen when 'n' is one"))); // expected-note{{member declaration nearly matches}} expected-note{{candidate disabled: chosen when 'n' is one}} static void s(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))); // expected-note2{{candidate disabled: chosen when 'n' is zero}} void conflict(int n) __attribute__((enable_if(n+n == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}} void conflict(int n) __attribute__((enable_if(n*2 == 10, "chosen when 'n' is five"))); // expected-note{{candidate function}} operator long() __attribute__((enable_if(true, "chosen on your platform"))); operator int() __attribute__((enable_if(false, "chosen on other platform"))); operator fp() __attribute__((enable_if(false, "never enabled"))) { return surrogate; } // expected-note{{conversion candidate of type 'int (*)(int)'}} // FIXME: the message is not displayed }; void X::f(int n) __attribute__((enable_if(n == 0, "chosen when 'n' is zero"))) // expected-note{{member declaration nearly matches}} expected-note{{candidate disabled: chosen when 'n' is zero}} { } void X::f(int n) __attribute__((enable_if(n == 2, "chosen when 'n' is two"))) // expected-error{{out-of-line definition of 'f' does not match any declaration in 'X'}} expected-note{{candidate disabled: chosen when 'n' is two}} { } __attribute__((deprecated)) constexpr int old() { return 0; } // expected-note2{{'old' has been explicitly marked deprecated here}} void deprec1(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}} void deprec2(int i) __attribute__((enable_if(old() == 0, "chosen when old() is zero"))); // expected-warning{{'old' is deprecated}} void overloaded(int); void overloaded(long); struct Nothing { };
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu | FileCheck %s // Verifying that we do, in fact, select the correct function in the following // cases. void foo(int m) __attribute__((overloadable, enable_if(m > 0, ""))); void foo(int m) __attribute__((overloadable)); // CHECK-LABEL: define void @test1 void test1() { // CHECK: store void (i32)* @_Z3fooi void (*p)(int) = foo; // CHECK: store void (i32)* @_Z3fooi void (*p2)(int) = &foo; // CHECK: store void (i32)* @_Z3fooi p = foo; // CHECK: store void (i32)* @_Z3fooi p = &foo; // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*) void *vp1 = (void*)&foo; // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*) void *vp2 = (void*)foo; // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*) vp1 = (void*)&foo; // CHECK: store i8* bitcast (void (i32)* @_Z3fooi to i8*) vp1 = (void*)foo; } void bar(int m) __attribute__((overloadable, enable_if(m > 0, ""))); void bar(int m) __attribute__((overloadable, enable_if(1, "")));
// RUN: %clang_cc1 -emit-llvm %s -o - -triple=x86_64-pc-linux-gnu| FileCheck %s // Test itanium mangling for attribute enable_if // CHECK: _Z5test1Ua9enable_ifIXeqfL0p_Li1EEEi void test1(int i) __attribute__((enable_if(i == 1, ""))) {} void ext(); // CHECK: _Z5test2Ua9enable_ifIXneadL_Z3extvELi0EEEi void test2(int i) __attribute__((enable_if(&ext != 0, ""))) {} // CHECK: _Z5test3Ua9enable_ifIXeqfL0p_Li1EEXeqfL0p0_Li2EEEii void test3(int i, int j) __attribute__((enable_if(i == 1, ""), enable_if(j == 2, ""))) {} // CHECK: _ZN5test4IdE1fEUa9enable_ifIXeqfL0p_Li1EEXeqfL0p0_Li2EEEi template <typename T> class test4 { virtual void f(int i, int j) __attribute__((enable_if(i == 1, ""))) __attribute__((enable_if(j == 2, ""))); }; template class test4<double>;