r224215 - AST: Limit zero-sized constexpr behavior to array types

David Majnemer david.majnemer at gmail.com
Sun Dec 14 00:40:48 PST 2014


Author: majnemer
Date: Sun Dec 14 02:40:47 2014
New Revision: 224215

URL: http://llvm.org/viewvc/llvm-project?rev=224215&view=rev
Log:
AST: Limit zero-sized constexpr behavior to array types

Restricting this "extension" to array types maximizes our standards
conformance while not miscompiling real-world programs.

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

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=224215&r1=224214&r2=224215&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Dec 14 02:40:47 2014
@@ -1426,7 +1426,9 @@ static bool isZeroSized(const LValue &Va
   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;
 }

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=224215&r1=224214&r2=224215&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Sun Dec 14 02:40:47 2014
@@ -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 {





More information about the cfe-commits mailing list