[PATCH] D42776: [Sema] Fix an assertion failure in constant expression evaluation of calls to functions with default arguments

Akira Hatanaka via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 11:49:25 PST 2018


ahatanak added inline comments.


================
Comment at: lib/AST/ExprConstant.cpp:5236
     if (Frame) {
-      Result.set(VD, Frame->Index);
+      Result.set({VD, Frame->Index});
       return true;
----------------
rsmith wrote:
> Hmm. We should be versioning local variables as well. Currently we'll accept invalid code such as:
> 
> ```
> constexpr int f() {
>   int *p = nullptr;
>   for (int k = 0; k != 2; ++k) {
>     int local_var = 0;
>     if (k == 0)
>       p = &local_var;
>     else
>       return *p;
>   }
> }
> static_assert(f() == 0);
> ```
I made changes to the constructor and destructor of ScopeRAII so that a version is pushed at the start of a new iteration. This fixes the FIXME in test/SemaCXX/constant-expression-cxx1y.cpp.


https://reviews.llvm.org/D42776





More information about the cfe-commits mailing list