<div class="gmail_quote">On Wed, Feb 15, 2012 at 11:46 AM, Matthieu Monrocq <span dir="ltr"><<a href="mailto:matthieu.monrocq@gmail.com">matthieu.monrocq@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote">Le 14 février 2012 22:38, Richard Smith <span dir="ltr"><<a href="mailto:richard-llvm@metafoo.co.uk" target="_blank">richard-llvm@metafoo.co.uk</a>></span> a écrit :<div><div class="h5"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: rsmith<br>
Date: Tue Feb 14 15:38:30 2012<br>
New Revision: 150510<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=150510&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=150510&view=rev</a><br>
Log:<br>
Pending clear answer from WG21 on whether core issue 903 is intended to apply to<br>
C++11 or just C++17, restrict the set of null pointer constants in C++11 mode<br>
back to those which were considered null in C++98.<br>
<br>
Modified:<br>
    cfe/trunk/include/clang/AST/Expr.h<br>
    cfe/trunk/lib/AST/Expr.cpp<br>
    cfe/trunk/lib/AST/ExprConstant.cpp<br>
    cfe/trunk/test/SemaCXX/nullptr.cpp<br>
<br>
Modified: cfe/trunk/include/clang/AST/Expr.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=150510&r1=150509&r2=150510&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=150510&r1=150509&r2=150510&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/include/clang/AST/Expr.h (original)<br>
+++ cfe/trunk/include/clang/AST/Expr.h Tue Feb 14 15:38:30 2012<br>
@@ -423,6 +423,10 @@<br>
                              bool isEvaluated = true) const;<br>
   bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) const;<br>
<br>
+  /// isCXX98IntegralConstantExpr - Return true if this expression is an<br>
+  /// integral constant expression in C++98. Can only be used in C++.<br>
+  bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const;<br>
+<br>
   /// isCXX11ConstantExpr - Return true if this expression is a constant<br>
   /// expression in C++11. Can only be used in C++.<br>
   ///<br>
<br>
Modified: cfe/trunk/lib/AST/Expr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=150510&r1=150509&r2=150510&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=150510&r1=150509&r2=150510&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/lib/AST/Expr.cpp (original)<br>
+++ cfe/trunk/lib/AST/Expr.cpp Tue Feb 14 15:38:30 2012<br>
@@ -2728,11 +2728,18 @@<br>
     return NPCK_NotNull;<br>
<br>
   // If we have an integer constant expression, we need to *evaluate* it and<br>
-  // test for the value 0.<br>
-  llvm::APSInt Result;<br>
-  bool IsNull = isIntegerConstantExpr(Result, Ctx) && Result == 0;<br>
+  // test for the value 0. Don't use the C++11 constant expression semantics<br>
+  // for this, for now; once the dust settles on core issue 903, we might only<br>
+  // allow a literal 0 here in C++11 mode.<br>
+  if (Ctx.getLangOptions().CPlusPlus0x) {<br>
+    if (!isCXX98IntegralConstantExpr(Ctx))<br>
+      return NPCK_NotNull;<br>
+  } else {<br>
+    if (!isIntegerConstantExpr(Ctx))<br>
+      return NPCK_NotNull;<br>
+  }<br>
<br>
-  return (IsNull ? NPCK_ZeroInteger : NPCK_NotNull);<br>
+  return (EvaluateKnownConstInt(Ctx) == 0) ? NPCK_ZeroInteger : NPCK_NotNull;<br>
 }<br>
<br>
 /// \brief If this expression is an l-value for an Objective C<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=150510&r1=150509&r2=150510&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=150510&r1=150509&r2=150510&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Feb 14 15:38:30 2012<br>
@@ -6435,12 +6435,17 @@<br>
   return true;<br>
 }<br>
<br>
+bool Expr::isCXX98IntegralConstantExpr(ASTContext &Ctx) const {<br>
+  return CheckICE(this, Ctx).Val == 0;<br>
+}<br>
+<br>
 bool Expr::isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result,<br>
                                SourceLocation *Loc) const {<br>
   // We support this checking in C++98 mode in order to diagnose compatibility<br>
   // issues.<br>
   assert(Ctx.getLangOptions().CPlusPlus);<br>
<br>
+  // Build evaluation settings.<br>
   Expr::EvalStatus Status;<br>
   llvm::SmallVector<PartialDiagnosticAt, 8> Diags;<br>
   Status.Diag = &Diags;<br>
<br>
Modified: cfe/trunk/test/SemaCXX/nullptr.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr.cpp?rev=150510&r1=150509&r2=150510&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr.cpp?rev=150510&r1=150509&r2=150510&view=diff</a><br>


==============================================================================<br>
--- cfe/trunk/test/SemaCXX/nullptr.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/nullptr.cpp Tue Feb 14 15:38:30 2012<br>
@@ -161,3 +161,14 @@<br>
<br>
   X2<nullptr, nullptr, nullptr, nullptr> x2;<br>
 }<br>
+<br>
+namespace null_pointer_constant {<br>
+<br>
+// Pending implementation of core issue 903, ensure we don't allow any of the<br>
+// C++11 constant evaluation semantics in null pointer constants.<br>
+struct S { int n; };<br>
+constexpr int null() { return 0; }<br>
+void *p = S().n; // expected-error {{cannot initialize}}<br>
+void *q = null(); // expected-error {{cannot initialize}}<br>
+<br>
+}<br>
<br></blockquote></div></div><div><br>Just for my curiosity: is it the discrepancy between C++98 and C++11 that Chandler mentionned you and he had discovered just right before GoingNative 2012 ? It really looks like it.</div>
</div></blockquote></div><div><br></div><div>Yes, exactly so. Fixing the language > providing good warnings. :-)</div><div><br></div><div>- Richard</div>