r290577 - Add a test for `const` folding introduced by r290297. NFC.

George Burgess IV via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 26 21:44:29 PST 2016


r290584 :)

On Mon, Dec 26, 2016 at 8:30 PM, George Burgess IV <
george.burgess.iv at gmail.com> wrote:

> SG; working on a follow-up now. Thanks!
>
> On Mon, Dec 26, 2016 at 8:26 PM, Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> On 26 December 2016 at 20:01, George Burgess IV via cfe-commits <
>> cfe-commits at lists.llvm.org> wrote:
>>
>>> Author: gbiv
>>> Date: Mon Dec 26 22:01:22 2016
>>> New Revision: 290577
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=290577&view=rev
>>> Log:
>>> Add a test for `const` folding introduced by r290297. NFC.
>>>
>>> AFAICT, we didn't add a test targeted at the new "const can sometimes
>>> act as constexpr" behavior introduced by r290297.
>>>
>>> Modified:
>>>     cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>>>
>>> Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/c
>>> onstant-expression-cxx1y.cpp?rev=290577&r1=290576&r2=290577&view=diff
>>> ============================================================
>>> ==================
>>> --- cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp (original)
>>> +++ cfe/trunk/test/SemaCXX/constant-expression-cxx1y.cpp Mon Dec 26
>>> 22:01:22 2016
>>> @@ -957,3 +957,20 @@ namespace PR27989 {
>>>    }
>>>    static_assert(f(0) == 1, "");
>>>  }
>>> +
>>> +namespace const_char {
>>> +template <int M, int N>
>>> +constexpr int sum(const char (&Arr)[N]) {
>>> +  static_assert(N >= M, "");
>>> +  int S = 0;
>>> +  for (unsigned I = 0; I != M; ++I)
>>> +    S += Arr[I];
>>> +  return S;
>>> +}
>>> +
>>> +// As an extension, we support evaluating some things that are `const`
>>> as though
>>> +// they were `constexpr`.
>>> +const char Cs[] = {'a', 'b', 'c'};
>>> +const int N = 2;
>>> +static_assert(sum<N>(Cs) == 'a' + 'b', "");
>>> +}
>>
>>
>> Hold on, this test should fail. It's OK to extend the set of things we
>> can constant-fold, but formal constant expression checking still needs to
>> be strict. (You should produce a CCEDiag from within the constant
>> expression evaluator to mark things that are not core constant expressions
>> but are permitted as an extension.)
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161226/313b3573/attachment-0001.html>


More information about the cfe-commits mailing list