xref: /llvm-project/clang/test/SemaCXX/enable_if-nested-call-with-valuedependent-param.cpp (revision d6acd0196b3378bdeb5193053e290d7194c4f72d)
1 // RUN: %clang_cc1 -fsyntax-only %s -std=c++14
2 
3 // Checks that Clang doesn't crash/assert on the nested call to "kaboom"
4 // in "bar()".
5 //
6 // This is an interesting test case for `ExprConstant.cpp`'s `CallStackFrame`
7 // because it triggers the following chain of events:
8 // 0. `CheckEnableIf` calls `EvaluateWithSubstitution`.
9 //  1. The outer call to "kaboom" gets evaluated.
10 //   2. The expr for "a" gets evaluated, it has a version X;
11 //      a temporary with the key (a, X) is created.
12 //     3. The inner call to "kaboom" gets evaluated.
13 //       4. The expr for "a" gets evaluated, it has a version Y;
14 //          a temporary with the key (a, Y) is created.
15 //       5. The expr for "b" gets evaluated, it has a version Y;
16 //          a temporary with the key (b, Y) is created.
17 //   6. `EvaluateWithSubstitution` looks at "b" but cannot evaluate it
18 //      because it's value-dependent (due to the call to "f.foo()").
19 //
20 // When `EvaluateWithSubstitution` bails out while evaluating the outer
21 // call, it attempts to fetch "b"'s param slot to clean it up.
22 //
23 // This used to cause an assertion failure in `getTemporary` because
24 // a temporary with the key "(b, Y)" (created at step 4) existed but
25 // not one for "(b, X)", which is what it was trying to fetch.
26 
27 template<typename T>
28 __attribute__((enable_if(true, "")))
kaboom(T a,T b)29 T kaboom(T a, T b) {
30   return b;
31 }
32 
33 struct A {
34   double foo();
35 };
36 
37 template <int>
38 struct B {
39   A &f;
40 
barB41   void bar() {
42     kaboom(kaboom(0.0, 1.0), f.foo());
43   }
44 };
45