majnemer updated this revision to Diff 49109. majnemer added a comment. - Refactor this change.
http://reviews.llvm.org/D17619 Files: lib/AST/ExprConstant.cpp test/SemaCXX/ms-const-member-expr.cpp Index: test/SemaCXX/ms-const-member-expr.cpp =================================================================== --- /dev/null +++ test/SemaCXX/ms-const-member-expr.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 %s -std=c++11 -fms-compatibility -fsyntax-only -verify + +struct S { + enum { E = 1 }; + static const int sdm = 1; +}; + +void f(S *s) { + char array[s->E] = { 0 }; +} + +extern S *s; +constexpr int e1 = s->E; + +S *side_effect(); // expected-note{{declared here}} +constexpr int e2 = // expected-error{{must be initialized by a constant expression}} + side_effect()->E; // expected-note{{cannot be used in a constant expression}} + +constexpr int e4 = s->sdm; Index: lib/AST/ExprConstant.cpp =================================================================== --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -4427,6 +4427,15 @@ void VisitIgnoredValue(const Expr *E) { EvaluateIgnoredValue(Info, E); } + + /// Potentially visit a MemberExpr's base expression. + void VisitIgnoredBaseExpression(const Expr *E) { + // While MSVC doesn't evaluate the base expression, it does diagnose the + // presence of side-effecting behavior. + if (Info.getLangOpts().MSVCCompat && !E->HasSideEffects(Info.Ctx)) + return; + VisitIgnoredValue(E); + } }; } @@ -4750,14 +4759,14 @@ bool LValueExprEvaluator::VisitMemberExpr(const MemberExpr *E) { // Handle static data members. if (const VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) { - VisitIgnoredValue(E->getBase()); + VisitIgnoredBaseExpression(E->getBase()); return VisitVarDecl(E, VD); } // Handle static member functions. if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->getMemberDecl())) { if (MD->isStatic()) { - VisitIgnoredValue(E->getBase()); + VisitIgnoredBaseExpression(E->getBase()); return Success(MD); } } @@ -6078,7 +6087,7 @@ } bool VisitMemberExpr(const MemberExpr *E) { if (CheckReferencedDecl(E, E->getMemberDecl())) { - VisitIgnoredValue(E->getBase()); + VisitIgnoredBaseExpression(E->getBase()); return true; }
Index: test/SemaCXX/ms-const-member-expr.cpp =================================================================== --- /dev/null +++ test/SemaCXX/ms-const-member-expr.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 %s -std=c++11 -fms-compatibility -fsyntax-only -verify + +struct S { + enum { E = 1 }; + static const int sdm = 1; +}; + +void f(S *s) { + char array[s->E] = { 0 }; +} + +extern S *s; +constexpr int e1 = s->E; + +S *side_effect(); // expected-note{{declared here}} +constexpr int e2 = // expected-error{{must be initialized by a constant expression}} + side_effect()->E; // expected-note{{cannot be used in a constant expression}} + +constexpr int e4 = s->sdm; Index: lib/AST/ExprConstant.cpp =================================================================== --- lib/AST/ExprConstant.cpp +++ lib/AST/ExprConstant.cpp @@ -4427,6 +4427,15 @@ void VisitIgnoredValue(const Expr *E) { EvaluateIgnoredValue(Info, E); } + + /// Potentially visit a MemberExpr's base expression. + void VisitIgnoredBaseExpression(const Expr *E) { + // While MSVC doesn't evaluate the base expression, it does diagnose the + // presence of side-effecting behavior. + if (Info.getLangOpts().MSVCCompat && !E->HasSideEffects(Info.Ctx)) + return; + VisitIgnoredValue(E); + } }; } @@ -4750,14 +4759,14 @@ bool LValueExprEvaluator::VisitMemberExpr(const MemberExpr *E) { // Handle static data members. if (const VarDecl *VD = dyn_cast<VarDecl>(E->getMemberDecl())) { - VisitIgnoredValue(E->getBase()); + VisitIgnoredBaseExpression(E->getBase()); return VisitVarDecl(E, VD); } // Handle static member functions. if (const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(E->getMemberDecl())) { if (MD->isStatic()) { - VisitIgnoredValue(E->getBase()); + VisitIgnoredBaseExpression(E->getBase()); return Success(MD); } } @@ -6078,7 +6087,7 @@ } bool VisitMemberExpr(const MemberExpr *E) { if (CheckReferencedDecl(E, E->getMemberDecl())) { - VisitIgnoredValue(E->getBase()); + VisitIgnoredBaseExpression(E->getBase()); return true; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits