From: George Burgess IV Date: Thu, 3 Dec 2015 20:54:58 +0000 (+0000) Subject: Add tests for `&enable_if_function` diagnostics. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f13bdea04027893a1f53e6f02318fba839d94022;p=clang Add tests for `&enable_if_function` diagnostics. The introduction of pass_object_size fixed a few bugs related to taking the address of a function with enable_if attributes. This patch adds tests for the cases that were fixed. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254646 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 645dbed21b..41aba09f3e 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -8833,7 +8833,6 @@ static bool checkAddressOfFunctionIsAvailable(Sema &S, const FunctionDecl *FD, SourceLocation Loc) { if (!isFunctionAlwaysEnabled(S.Context, FD)) { if (Complain) { - // FIXME(gbiv): Both diagnostics below lack tests. We should add tests. if (InOverloadResolution) S.Diag(FD->getLocStart(), diag::note_addrof_ovl_candidate_disabled_by_enable_if_attr); diff --git a/test/Sema/enable_if.c b/test/Sema/enable_if.c index 0ee642e2ee..0cd9c48f42 100644 --- a/test/Sema/enable_if.c +++ b/test/Sema/enable_if.c @@ -136,4 +136,10 @@ void test7() { void *p3 = (void*)&f3; // expected-error{{address of overloaded function 'f3' does not match required type 'void'}} expected-note@131{{candidate function made ineligible by enable_if}} expected-note@132{{candidate function made ineligible by enable_if}} void *p4 = (void*)f3; // expected-error{{address of overloaded function 'f3' does not match required type 'void'}} expected-note@131{{candidate function made ineligible by enable_if}} expected-note@132{{candidate function made ineligible by enable_if}} } + +void f4(int m) __attribute__((enable_if(0, ""))); +void test8() { + void (*p1)(int) = &f4; // expected-error{{cannot take address of function 'f4' becuase it has one or more non-tautological enable_if conditions}} + void (*p2)(int) = f4; // expected-error{{cannot take address of function 'f4' becuase it has one or more non-tautological enable_if conditions}} +} #endif diff --git a/test/SemaCXX/enable_if.cpp b/test/SemaCXX/enable_if.cpp index b32bcd01f4..cd8241808c 100644 --- a/test/SemaCXX/enable_if.cpp +++ b/test/SemaCXX/enable_if.cpp @@ -233,4 +233,23 @@ namespace FnPtrs { a = templatedConflict; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@226{{candidate function}} expected-note@228{{candidate function}} a = &templatedConflict; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@226{{candidate function}} expected-note@228{{candidate function}} } + + int ovlNoCandidate(int m) __attribute__((enable_if(false, ""))); + int ovlNoCandidate(int m) __attribute__((enable_if(0, ""))); + void test7() { + int (*p)(int) = ovlNoCandidate; // expected-error{{address of overloaded function 'ovlNoCandidate' does not match required type}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}} + int (*p2)(int) = &ovlNoCandidate; // expected-error{{address of overloaded function 'ovlNoCandidate' does not match required type}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}} + int (*a)(int); + a = ovlNoCandidate; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}} + a = &ovlNoCandidate; // expected-error{{assigning to 'int (*)(int)' from incompatible type ''}} expected-note@237{{made ineligible by enable_if}} expected-note@238{{made ineligible by enable_if}} + } + + int noOvlNoCandidate(int m) __attribute__((enable_if(false, ""))); + void test8() { + int (*p)(int) = noOvlNoCandidate; // expected-error{{cannot take address of function 'noOvlNoCandidate' becuase it has one or more non-tautological enable_if conditions}} + int (*p2)(int) = &noOvlNoCandidate; // expected-error{{cannot take address of function 'noOvlNoCandidate' becuase it has one or more non-tautological enable_if conditions}} + int (*a)(int); + a = noOvlNoCandidate; // expected-error{{cannot take address of function 'noOvlNoCandidate' becuase it has one or more non-tautological enable_if conditions}} + a = &noOvlNoCandidate; // expected-error{{cannot take address of function 'noOvlNoCandidate' becuase it has one or more non-tautological enable_if conditions}} + } }