<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Dec 11, 2014 at 11:36 AM, David Majnemer <span dir="ltr"><<a href="mailto:david.majnemer@gmail.com" target="_blank">david.majnemer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: majnemer<br>
Date: Thu Dec 11 13:36:24 2014<br>
New Revision: 224040<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=224040&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=224040&view=rev</a><br>
Log:<br>
AST: Incomplete types might be zero sized<br>
<br>
Comparing the address of an object with an incomplete type might return<br>
true with a 'distinct' object if the former has a size of zero.<br>
However, such an object should compare unequal with null.<br>
<br>
Modified:<br>
cfe/trunk/lib/AST/ExprConstant.cpp<br>
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
<br>
Modified: cfe/trunk/lib/AST/ExprConstant.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=224040&r1=224039&r2=224040&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=224040&r1=224039&r2=224040&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Dec 11 13:36:24 2014<br>
@@ -1424,8 +1424,11 @@ static bool IsWeakLValue(const LValue &V<br>
<br>
static bool isZeroSized(const LValue &Value) {<br>
const ValueDecl *Decl = GetLValueBaseDecl(Value);<br>
- return Decl && isa<VarDecl>(Decl) &&<br>
- Decl->getASTContext().getTypeSize(Decl->getType()) == 0;<br>
+ if (Decl && isa<VarDecl>(Decl)) {<br>
+ QualType Ty = Decl->getType();<br>
+ return Ty->isIncompleteType() || Decl->getASTContext().getTypeSize(Ty) == 0;<br>
+ }<br>
+ return false;<br>
}<br>
<br>
static bool EvalPointerValueAsBool(const APValue &Value, bool &Result) {<br>
@@ -6987,7 +6990,8 @@ bool IntExprEvaluator::VisitBinaryOperat<br>
return Error(E);<br>
// We can't tell whether an object is at the same address as another<br>
// zero sized object.<br>
- if (isZeroSized(LHSValue) || isZeroSized(RHSValue))<br>
+ if ((RHSValue.Base && isZeroSized(LHSValue)) ||<br>
+ (LHSValue.Base && isZeroSized(RHSValue)))<br>
return Error(E);<br>
// Pointers with different bases cannot represent the same object.<br>
// (Note that clang defaults to -fmerge-all-constants, which can<br>
<br>
Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=224040&r1=224039&r2=224040&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=224040&r1=224039&r2=224040&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Thu Dec 11 13:36:24 2014<br>
@@ -1960,4 +1960,12 @@ namespace PR21786 {<br>
extern void (*start[])();<br>
extern void (*end[])();<br>
static_assert(&start != &end, ""); // expected-error {{constant expression}}<br>
+<br>
+ struct Foo;<br>
+ struct Bar {<br>
+ static const Foo x;<br>
+ static const Foo y;<br>
+ };<br>
+ static_assert(&Bar::x != nullptr, "");<br>
+ static_assert(&Bar::x != &Bar::y, ""); // expected-error {{constant expression}}<br></blockquote><div><br></div><div>This is a rejects-valid. Per the C++11 rules, the above is a constant expression that is required to evaluate to 'true'.</div></div></div></div>