r194441 - -fms-compatibility: Use C++98 null pointer constant rules

Reid Kleckner reid at kleckner.net
Mon Nov 11 18:22:35 PST 2013


Author: rnk
Date: Mon Nov 11 20:22:34 2013
New Revision: 194441

URL: http://llvm.org/viewvc/llvm-project?rev=194441&view=rev
Log:
-fms-compatibility: Use C++98 null pointer constant rules

Patch by Will Wilson!

Modified:
    cfe/trunk/lib/AST/Expr.cpp
    cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=194441&r1=194440&r2=194441&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Mon Nov 11 20:22:34 2013
@@ -3051,7 +3051,8 @@ bool Expr::hasNonTrivialCall(ASTContext
 Expr::NullPointerConstantKind
 Expr::isNullPointerConstant(ASTContext &Ctx,
                             NullPointerConstantValueDependence NPC) const {
-  if (isValueDependent() && !Ctx.getLangOpts().CPlusPlus11) {
+  if (isValueDependent() &&
+      (!Ctx.getLangOpts().CPlusPlus11 || Ctx.getLangOpts().MicrosoftMode)) {
     switch (NPC) {
     case NPC_NeverValueDependent:
       llvm_unreachable("Unexpected value dependent expression!");
@@ -3133,8 +3134,13 @@ Expr::isNullPointerConstant(ASTContext &
   if (Ctx.getLangOpts().CPlusPlus11) {
     // C++11 [conv.ptr]p1: A null pointer constant is an integer literal with
     // value zero or a prvalue of type std::nullptr_t.
+    // Microsoft mode permits C++98 rules reflecting MSVC behavior.
     const IntegerLiteral *Lit = dyn_cast<IntegerLiteral>(this);
-    return (Lit && !Lit->getValue()) ? NPCK_ZeroLiteral : NPCK_NotNull;
+    if (Lit && !Lit->getValue())
+      return NPCK_ZeroLiteral;
+    else if (!Ctx.getLangOpts().MicrosoftMode ||
+             !isCXX98IntegralConstantExpr(Ctx))
+      return NPCK_NotNull;
   } else {
     // If we have an integer constant expression, we need to *evaluate* it and
     // test for the value 0.

Modified: cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp?rev=194441&r1=194440&r2=194441&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftCompatibility.cpp Mon Nov 11 20:22:34 2013
@@ -178,3 +178,19 @@ namespace PR11791 {
     del((void*)a);  // expected-note {{in instantiation of function template specialization}}
   }
 }
+
+namespace IntToNullPtrConv {
+  struct Foo {
+    static const int ZERO = 0;
+    typedef void (Foo::*MemberFcnPtr)();
+  };
+
+  struct Bar {
+    const Foo::MemberFcnPtr pB;
+  };
+
+  Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
+
+  template<int N> int *get_n() { return N; }   // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
+  int *g_nullptr = get_n<0>();  // expected-note {{in instantiation of function template specialization}}
+}





More information about the cfe-commits mailing list