]> granicus.if.org Git - clang/commitdiff
-fms-compatibility: Use C++98 null pointer constant rules
authorReid Kleckner <reid@kleckner.net>
Tue, 12 Nov 2013 02:22:34 +0000 (02:22 +0000)
committerReid Kleckner <reid@kleckner.net>
Tue, 12 Nov 2013 02:22:34 +0000 (02:22 +0000)
Patch by Will Wilson!

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

lib/AST/Expr.cpp
test/SemaCXX/MicrosoftCompatibility.cpp

index e467883288ba71919f70151d09693ae4e55aa4d4..8bbf2ff546438d3cc7d7c97687fa34fde0a225a5 100644 (file)
@@ -3051,7 +3051,8 @@ bool Expr::hasNonTrivialCall(ASTContext &Ctx) {
 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 &Ctx,
   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.
index 6a48f36801bdfe887b86f26002a30010e04bef4d..05037ac6a0d03b56fc26ce1c27efd157abe9c528 100644 (file)
@@ -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}}
+}