Le 14 février 2012 22:38, Richard Smith <[email protected]> a écrit :
> Author: rsmith > Date: Tue Feb 14 15:38:30 2012 > New Revision: 150510 > > URL: http://llvm.org/viewvc/llvm-project?rev=150510&view=rev > Log: > Pending clear answer from WG21 on whether core issue 903 is intended to > apply to > C++11 or just C++17, restrict the set of null pointer constants in C++11 > mode > back to those which were considered null in C++98. > > Modified: > cfe/trunk/include/clang/AST/Expr.h > cfe/trunk/lib/AST/Expr.cpp > cfe/trunk/lib/AST/ExprConstant.cpp > cfe/trunk/test/SemaCXX/nullptr.cpp > > Modified: cfe/trunk/include/clang/AST/Expr.h > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=150510&r1=150509&r2=150510&view=diff > > ============================================================================== > --- cfe/trunk/include/clang/AST/Expr.h (original) > +++ cfe/trunk/include/clang/AST/Expr.h Tue Feb 14 15:38:30 2012 > @@ -423,6 +423,10 @@ > bool isEvaluated = true) const; > bool isIntegerConstantExpr(ASTContext &Ctx, SourceLocation *Loc = 0) > const; > > + /// isCXX98IntegralConstantExpr - Return true if this expression is an > + /// integral constant expression in C++98. Can only be used in C++. > + bool isCXX98IntegralConstantExpr(ASTContext &Ctx) const; > + > /// isCXX11ConstantExpr - Return true if this expression is a constant > /// expression in C++11. Can only be used in C++. > /// > > Modified: cfe/trunk/lib/AST/Expr.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=150510&r1=150509&r2=150510&view=diff > > ============================================================================== > --- cfe/trunk/lib/AST/Expr.cpp (original) > +++ cfe/trunk/lib/AST/Expr.cpp Tue Feb 14 15:38:30 2012 > @@ -2728,11 +2728,18 @@ > return NPCK_NotNull; > > // If we have an integer constant expression, we need to *evaluate* it > and > - // test for the value 0. > - llvm::APSInt Result; > - bool IsNull = isIntegerConstantExpr(Result, Ctx) && Result == 0; > + // test for the value 0. Don't use the C++11 constant expression > semantics > + // for this, for now; once the dust settles on core issue 903, we might > only > + // allow a literal 0 here in C++11 mode. > + if (Ctx.getLangOptions().CPlusPlus0x) { > + if (!isCXX98IntegralConstantExpr(Ctx)) > + return NPCK_NotNull; > + } else { > + if (!isIntegerConstantExpr(Ctx)) > + return NPCK_NotNull; > + } > > - return (IsNull ? NPCK_ZeroInteger : NPCK_NotNull); > + return (EvaluateKnownConstInt(Ctx) == 0) ? NPCK_ZeroInteger : > NPCK_NotNull; > } > > /// \brief If this expression is an l-value for an Objective C > > Modified: cfe/trunk/lib/AST/ExprConstant.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=150510&r1=150509&r2=150510&view=diff > > ============================================================================== > --- cfe/trunk/lib/AST/ExprConstant.cpp (original) > +++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Feb 14 15:38:30 2012 > @@ -6435,12 +6435,17 @@ > return true; > } > > +bool Expr::isCXX98IntegralConstantExpr(ASTContext &Ctx) const { > + return CheckICE(this, Ctx).Val == 0; > +} > + > bool Expr::isCXX11ConstantExpr(ASTContext &Ctx, APValue *Result, > SourceLocation *Loc) const { > // We support this checking in C++98 mode in order to diagnose > compatibility > // issues. > assert(Ctx.getLangOptions().CPlusPlus); > > + // Build evaluation settings. > Expr::EvalStatus Status; > llvm::SmallVector<PartialDiagnosticAt, 8> Diags; > Status.Diag = &Diags; > > Modified: cfe/trunk/test/SemaCXX/nullptr.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/nullptr.cpp?rev=150510&r1=150509&r2=150510&view=diff > > ============================================================================== > --- cfe/trunk/test/SemaCXX/nullptr.cpp (original) > +++ cfe/trunk/test/SemaCXX/nullptr.cpp Tue Feb 14 15:38:30 2012 > @@ -161,3 +161,14 @@ > > X2<nullptr, nullptr, nullptr, nullptr> x2; > } > + > +namespace null_pointer_constant { > + > +// Pending implementation of core issue 903, ensure we don't allow any of > the > +// C++11 constant evaluation semantics in null pointer constants. > +struct S { int n; }; > +constexpr int null() { return 0; } > +void *p = S().n; // expected-error {{cannot initialize}} > +void *q = null(); // expected-error {{cannot initialize}} > + > +} > > 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. --Matthieu
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
