On 26 December 2016 at 20:01, George Burgess IV via cfe-commits < cfe-commits@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/constant-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.)
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits