]> granicus.if.org Git - clang/commitdiff
constexpr: casts to void* are allowed in constant expressions, don't set the
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 15 Jan 2012 03:25:41 +0000 (03:25 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 15 Jan 2012 03:25:41 +0000 (03:25 +0000)
designator invalid. (Since we can't read the value of such a pointer, this only
affects the quality of diagnostics.)

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

lib/AST/ExprConstant.cpp
test/SemaCXX/constant-expression-cxx11.cpp

index ec5111579a213f12d04f7fdd584177ab2a4ee582..ae68e19d89e058dac6bffb5f04d5aa4c3acf2a92 100644 (file)
@@ -2695,19 +2695,19 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr* E) {
   case CK_CPointerToObjCPointerCast:
   case CK_BlockPointerToObjCPointerCast:
   case CK_AnyPointerToBlockPointerCast:
+    if (!Visit(SubExpr))
+      return false;
     // Bitcasts to cv void* are static_casts, not reinterpret_casts, so are
     // permitted in constant expressions in C++11. Bitcasts from cv void* are
     // also static_casts, but we disallow them as a resolution to DR1312.
     if (!E->getType()->isVoidPointerType()) {
+      Result.Designator.setInvalid();
       if (SubExpr->getType()->isVoidPointerType())
         CCEDiag(E, diag::note_constexpr_invalid_cast)
           << 3 << SubExpr->getType();
       else
         CCEDiag(E, diag::note_constexpr_invalid_cast) << 2;
     }
-    if (!Visit(SubExpr))
-      return false;
-    Result.Designator.setInvalid();
     return true;
 
   case CK_DerivedToBase:
index d80339fe5f13c54550c2cdfbe2a5ed38689ec22b..e20f8f32b57d4f30cd8afb9bb639f074ef9fed4e 100644 (file)
@@ -527,7 +527,7 @@ struct D {
 static_assert(D().c.n == 42, "");
 
 struct E {
-  constexpr E() : p(&p) {} // expected-note {{pointer to temporary cannot be used to initialize a member in a constant expression}}
+  constexpr E() : p(&p) {} // expected-note {{pointer to subobject of temporary cannot be used to initialize a member in a constant expression}}
   void *p;
 };
 constexpr const E &e1 = E(); // expected-error {{constant expression}} expected-note {{in call to 'E()'}} expected-note {{temporary created here}}