]> granicus.if.org Git - clang/commitdiff
AST: Limit zero-sized constexpr behavior to array types
authorDavid Majnemer <david.majnemer@gmail.com>
Sun, 14 Dec 2014 08:40:47 +0000 (08:40 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sun, 14 Dec 2014 08:40:47 +0000 (08:40 +0000)
Restricting this "extension" to array types maximizes our standards
conformance while not miscompiling real-world programs.

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

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

index 417f7931df47a6b6acd03b22db56a88065250fa8..ad36e76bea4586995e278397e3b7e766f73878e9 100644 (file)
@@ -1426,7 +1426,9 @@ static bool isZeroSized(const LValue &Value) {
   const ValueDecl *Decl = GetLValueBaseDecl(Value);
   if (Decl && isa<VarDecl>(Decl)) {
     QualType Ty = Decl->getType();
-    return Ty->isIncompleteType() || Decl->getASTContext().getTypeSize(Ty) == 0;
+    if (Ty->isArrayType())
+      return Ty->isIncompleteType() ||
+             Decl->getASTContext().getTypeSize(Ty) == 0;
   }
   return false;
 }
index cf317950c7724ceb3ee4d822da7c8139b25ace2d..dbb1255ef1c899e13abcc7b2d087fb88700897f9 100644 (file)
@@ -1960,6 +1960,7 @@ namespace PR21786 {
   extern void (*start[])();
   extern void (*end[])();
   static_assert(&start != &end, ""); // expected-error {{constant expression}}
+  static_assert(&start != nullptr, "");
 
   struct Foo;
   struct Bar {
@@ -1967,7 +1968,7 @@ namespace PR21786 {
     static const Foo y;
   };
   static_assert(&Bar::x != nullptr, "");
-  static_assert(&Bar::x != &Bar::y, ""); // expected-error {{constant expression}}
+  static_assert(&Bar::x != &Bar::y, "");
 }
 
 namespace PR21859 {