]> granicus.if.org Git - clang/commitdiff
Add tests for `&enable_if_function` diagnostics.
authorGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 3 Dec 2015 20:54:58 +0000 (20:54 +0000)
committerGeorge Burgess IV <george.burgess.iv@gmail.com>
Thu, 3 Dec 2015 20:54:58 +0000 (20:54 +0000)
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

lib/Sema/SemaOverload.cpp
test/Sema/enable_if.c
test/SemaCXX/enable_if.cpp

index 645dbed21ba04923cfa6fcd0031ad4fe5511974d..41aba09f3ee7d263cff0602377bd47cb8e930629 100644 (file)
@@ -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);
index 0ee642e2ee772660759628a9e72feacceaa9292b..0cd9c48f42b58a9a5c0ab8324b7302665ef7a070 100644 (file)
@@ -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
index b32bcd01f4206013ff325b55b32cf0bf5e23224d..cd8241808c94623728e6ed12b98c64769d641120 100644 (file)
@@ -233,4 +233,23 @@ namespace FnPtrs {
     a = templatedConflict<int>; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function type>'}} expected-note@226{{candidate function}} expected-note@228{{candidate function}}
     a = &templatedConflict<int>; // expected-error{{assigning to 'int (*)(int)' from incompatible type '<overloaded function 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 '<overloaded function 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 '<overloaded function 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}}
+  }
 }