]> granicus.if.org Git - clang/commitdiff
Don't forget to evaluate the subexpression in a null pointer cast. If we're
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 8 Apr 2012 08:02:07 +0000 (08:02 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 8 Apr 2012 08:02:07 +0000 (08:02 +0000)
converting from std::nullptr_t, the subexpression might have side-effects.

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

lib/AST/ExprConstant.cpp
test/CodeGenCXX/const-init-cxx11.cpp

index 4ef169d18995cab25e136096e19fce2d593ebdc6..435d94c1d47eeb7b19d6cc885199fbca96cef359 100644 (file)
@@ -3178,6 +3178,7 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr* E) {
     return HandleBaseToDerivedCast(Info, E, Result);
 
   case CK_NullToPointer:
+    VisitIgnoredValue(E->getSubExpr());
     return ZeroInitialization(E);
 
   case CK_IntegralToPointer: {
@@ -3276,6 +3277,7 @@ bool MemberPointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
     return ExprEvaluatorBaseTy::VisitCastExpr(E);
 
   case CK_NullToMemberPointer:
+    VisitIgnoredValue(E->getSubExpr());
     return ZeroInitialization(E);
 
   case CK_BaseToDerivedMemberPointer: {
index c6250c6d96686bc0b42dd0d41cd1e001f5359190..c745deebf04b5ac093aad3d9e20a7fa338f70e77 100644 (file)
@@ -414,3 +414,12 @@ namespace InitFromConst {
     consume(a);
   }
 }
+
+namespace Null {
+  decltype(nullptr) null();
+  // CHECK: call {{.*}} @_ZN4Null4nullEv(
+  int *p = null();
+  struct S {};
+  // CHECK: call {{.*}} @_ZN4Null4nullEv(
+  int S::*q = null();
+}