<div class="gmail_quote">On Mon, Apr 9, 2012 at 5:22 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com">eli.friedman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wed, Mar 14, 2012 at 9:53 PM, Richard Smith<br>
<<a href="mailto:richard-llvm@metafoo.co.uk">richard-llvm@metafoo.co.uk</a>> wrote:<br>
</div><div><div class="h5">> Author: rsmith<br>
> Date: Wed Mar 14 23:53:45 2012<br>
> New Revision: 152775<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=152775&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=152775&view=rev</a><br>
> Log:<br>
> Unrevert r152761 (reverted in r152772) with a fix for the issue which was<br>
> breaking bootstrap. No test yet: it's quite hard to tickle the failure case.<br>
> The specific testcase for this wouldn't be useful for testing anything more<br>
> general than a reintroduction of this precise bug in any case.<br>
><br>
> Modified:<br>
>    cfe/trunk/lib/AST/ExprConstant.cpp<br>
><br>
> Modified: cfe/trunk/lib/AST/ExprConstant.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=152775&r1=152774&r2=152775&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=152775&r1=152774&r2=152775&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/AST/ExprConstant.cpp (original)<br>
> +++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Mar 14 23:53:45 2012<br>
> @@ -480,9 +480,19 @@<br>
>       return OptionalDiagnostic();<br>
>     }<br>
><br>
> +    OptionalDiagnostic Diag(const Expr *E, diag::kind DiagId<br>
> +                              = diag::note_invalid_subexpr_in_const_expr,<br>
> +                            unsigned ExtraNotes = 0) {<br>
> +      if (EvalStatus.Diag)<br>
> +        return Diag(E->getExprLoc(), DiagId, ExtraNotes);<br>
> +      HasActiveDiagnostic = false;<br>
> +      return OptionalDiagnostic();<br>
> +    }<br>
> +<br>
>     /// Diagnose that the evaluation does not produce a C++11 core constant<br>
>     /// expression.<br>
> -    OptionalDiagnostic CCEDiag(SourceLocation Loc, diag::kind DiagId<br>
> +    template<typename LocArg><br>
> +    OptionalDiagnostic CCEDiag(LocArg Loc, diag::kind DiagId<br>
>                                  = diag::note_invalid_subexpr_in_const_expr,<br>
>                                unsigned ExtraNotes = 0) {<br>
>       // Don't override a previous diagnostic.<br>
> @@ -556,7 +566,7 @@<br>
>   if (Invalid)<br>
>     return false;<br>
>   if (isOnePastTheEnd()) {<br>
> -    Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_past_end_subobject)<br>
> +    Info.CCEDiag(E, diag::note_constexpr_past_end_subobject)<br>
>       << CSK;<br>
>     setInvalid();<br>
>     return false;<br>
> @@ -567,11 +577,11 @@<br>
>  void SubobjectDesignator::diagnosePointerArithmetic(EvalInfo &Info,<br>
>                                                     const Expr *E, uint64_t N) {<br>
>   if (MostDerivedPathLength == Entries.size() && MostDerivedArraySize)<br>
> -    Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_array_index)<br>
> +    Info.CCEDiag(E, diag::note_constexpr_array_index)<br>
>       << static_cast<int>(N) << /*array*/ 0<br>
>       << static_cast<unsigned>(MostDerivedArraySize);<br>
>   else<br>
> -    Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_array_index)<br>
> +    Info.CCEDiag(E, diag::note_constexpr_array_index)<br>
>       << static_cast<int>(N) << /*non-array*/ 1;<br>
>   setInvalid();<br>
>  }<br>
> @@ -730,7 +740,7 @@<br>
>       if (Designator.Invalid)<br>
>         return false;<br>
>       if (!Base) {<br>
> -        Info.CCEDiag(E->getExprLoc(), diag::note_constexpr_null_subobject)<br>
> +        Info.CCEDiag(E, diag::note_constexpr_null_subobject)<br>
>           << CSK;<br>
>         Designator.setInvalid();<br>
>         return false;<br>
> @@ -741,27 +751,30 @@<br>
>     // Check this LValue refers to an object. If not, set the designator to be<br>
>     // invalid and emit a diagnostic.<br>
>     bool checkSubobject(EvalInfo &Info, const Expr *E, CheckSubobjectKind CSK) {<br>
> +      // Outside C++11, do not build a designator referring to a subobject of<br>
> +      // any object: we won't use such a designator for anything.<br>
> +      if (!Info.getLangOpts().CPlusPlus0x)<br>
> +        Designator.setInvalid();<br>
<br>
</div></div>The comment here isn't completely correct: this check affects whether<br>
we accept the expression "FOOBAR"[3] as a constant expression in C.<br>
And I've just run into code C that started using that construct. :(<br>
Any suggestions?</blockquote><div><br></div><div>If we just want to support folding this specific case, I think it should be sufficient to disable this check if Base is a StringLiteral.</div></div>