r181758 - Suppress bogus "use of undefined constexpr function" error if the function body

Richard Smith richard-llvm at metafoo.co.uk
Mon May 13 22:18:44 PDT 2013


Author: rsmith
Date: Tue May 14 00:18:44 2013
New Revision: 181758

URL: http://llvm.org/viewvc/llvm-project?rev=181758&view=rev
Log:
Suppress bogus "use of undefined constexpr function" error if the function body
was erroneous and got discarded.

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
    cfe/trunk/test/SemaCXX/enum-unscoped-nonexistent.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=181758&r1=181757&r2=181758&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue May 14 00:18:44 2013
@@ -3161,6 +3161,11 @@ static bool CheckConstexprFunction(EvalI
       Declaration->isConstexpr())
     return false;
 
+  // Bail out with no diagnostic if the function declaration itself is invalid.
+  // We will have produced a relevant diagnostic while parsing it.
+  if (Declaration->isInvalidDecl())
+    return false;
+
   // Can we evaluate this function call?
   if (Definition && Definition->isConstexpr() && !Definition->isInvalidDecl())
     return true;

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=181758&r1=181757&r2=181758&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Tue May 14 00:18:44 2013
@@ -1503,3 +1503,11 @@ namespace PR15884 {
   // expected-note at -3 {{pointer to temporary is not a constant expression}}
   // expected-note at -4 {{temporary created here}}
 }
+
+namespace AfterError {
+  // FIXME: Suppress the 'no return statements' diagnostic if the body is invalid.
+  constexpr int error() { // expected-error {{no return statement}}
+    return foobar; // expected-error {{undeclared identifier}}
+  }
+  constexpr int k = error(); // expected-error {{must be initialized by a constant expression}}
+}

Modified: cfe/trunk/test/SemaCXX/enum-unscoped-nonexistent.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-unscoped-nonexistent.cpp?rev=181758&r1=181757&r2=181758&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum-unscoped-nonexistent.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum-unscoped-nonexistent.cpp Tue May 14 00:18:44 2013
@@ -6,7 +6,7 @@ struct Base {
 template<typename T> struct S : Base {
   enum E : int;
   constexpr int f() const;
-  constexpr int g() const; // expected-note {{declared here}}
+  constexpr int g() const;
   void h();
 };
 template<> enum S<char>::E : int {}; // expected-note {{enum 'S<char>::E' was explicitly specialized here}}
@@ -23,7 +23,7 @@ static_assert(S<int>().f() == 1, "");
 // The unqualified-id here names a member of the current instantiation, which
 // bizarrely might not exist in some instantiations.
 template<typename T> constexpr int S<T>::g() const { return b; } // expected-error {{enumerator 'b' does not exist in instantiation of 'S<char>'}}
-static_assert(S<char>().g() == 1, ""); // expected-note {{here}} expected-error {{not an integral constant expression}} expected-note {{undefined}}
+static_assert(S<char>().g() == 1, ""); // expected-note {{here}} expected-error {{not an integral constant expression}}
 static_assert(S<short>().g() == 2, "");
 static_assert(S<long>().g() == 8, "");
 





More information about the cfe-commits mailing list