[cfe-commits] r166898 - in /cfe/trunk: lib/Sema/SemaDecl.cpp test/SemaCXX/constant-expression-cxx11.cpp test/SemaCXX/cxx11-crashes.cpp

Richard Smith richard-llvm at metafoo.co.uk
Sat Oct 27 23:18:02 PDT 2012


Author: rsmith
Date: Sun Oct 28 01:18:02 2012
New Revision: 166898

URL: http://llvm.org/viewvc/llvm-project?rev=166898&view=rev
Log:
When determining whether to try evaluating the initializer of a variable, check
whether the initializer is value-dependent rather than whether we are in a
dependent context. This allows us to detect some errors sooner, and fixes a
crash-on-invalid if a dependent type leaks out to a non-dependent context in
error recovery.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
    cfe/trunk/test/SemaCXX/cxx11-crashes.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=166898&r1=166897&r2=166898&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Oct 28 01:18:02 2012
@@ -7201,7 +7201,7 @@
   Expr *Init = var->getInit();
   bool IsGlobal = var->hasGlobalStorage() && !var->isStaticLocal();
 
-  if (!var->getDeclContext()->isDependentContext() && Init) {
+  if (Init && !Init->isValueDependent()) {
     if (IsGlobal && !var->isConstexpr() &&
         getDiagnostics().getDiagnosticLevel(diag::warn_global_constructor,
                                             var->getLocation())

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=166898&r1=166897&r2=166898&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Sun Oct 28 01:18:02 2012
@@ -521,12 +521,19 @@
 
 struct I { int n; typedef I V[10]; };
 I::V x, y;
-template<bool B> struct S {
+int g(); // expected-note {{here}}
+template<bool B, typename T> struct S : T {
   int k;
   void f() {
     I::V &cells = B ? x : y;
     I &i = cells[k];
     switch (i.n) {}
+
+    constexpr int n = g(); // \
+    // expected-error {{must be initialized by a constant expression}} \
+    // expected-note {{non-constexpr function 'g'}}
+
+    constexpr int m = this->g(); // ok, could be constexpr
   }
 };
 

Modified: cfe/trunk/test/SemaCXX/cxx11-crashes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx11-crashes.cpp?rev=166898&r1=166897&r2=166898&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/cxx11-crashes.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx11-crashes.cpp Sun Oct 28 01:18:02 2012
@@ -62,3 +62,15 @@
 }
 
 }
+
+namespace b6981007 {
+  struct S {}; // expected-note 3{{candidate}}
+  void f() {
+    S s(1, 2, 3); // expected-error {{no matching}}
+    for (auto x : s) {
+      // We used to attempt to evaluate the initializer of this variable,
+      // and crash because it has an undeduced type.
+      const int &n(x);
+    }
+  }
+}





More information about the cfe-commits mailing list