]> granicus.if.org Git - clang/commitdiff
Sema: Don't crash when variable is redefined as a constexpr function
authorDavid Majnemer <david.majnemer@gmail.com>
Fri, 9 Jan 2015 10:33:23 +0000 (10:33 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Fri, 9 Jan 2015 10:33:23 +0000 (10:33 +0000)
We have a diagnostic describing that constexpr changed in C++14 when
compiling in C++11 mode.  While doing this, it examines the previous
declaration and assumes that it is a function.  However it is possible,
in the context of error recovery, for this to not be the case.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@225518 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/constant-expression-cxx11.cpp

index 970b2ecd72c2360224d39369c0d3051f9447fe5c..46cd285f5e8cc87d3aa90e2a6fee68796dd91dad 100644 (file)
@@ -7885,7 +7885,7 @@ bool Sema::CheckFunctionDeclaration(Scope *S, FunctionDecl *NewFD,
       (MD->getTypeQualifiers() & Qualifiers::Const) == 0) {
     CXXMethodDecl *OldMD = nullptr;
     if (OldDecl)
-      OldMD = dyn_cast<CXXMethodDecl>(OldDecl->getAsFunction());
+      OldMD = dyn_cast_or_null<CXXMethodDecl>(OldDecl->getAsFunction());
     if (!OldMD || !OldMD->isStatic()) {
       const FunctionProtoType *FPT =
         MD->getType()->castAs<FunctionProtoType>();
index d8f6f0876a8b17fee2fb31df551e09fbdfa5f2cb..14c0ae320d77ca12cc356d5297f661e157fee28a 100644 (file)
@@ -1979,3 +1979,8 @@ namespace PR21859 {
   constexpr int Fun() { return; } // expected-error {{non-void constexpr function 'Fun' should return a value}}
   constexpr int Var = Fun(); // expected-error {{constexpr variable 'Var' must be initialized by a constant expression}}
 }
+
+struct InvalidRedef {
+  int f; // expected-note{{previous definition is here}}
+  constexpr int f(void); // expected-error{{redefinition of 'f'}} expected-warning{{will not be implicitly 'const'}}
+};