[clang] [Clang][CWG1815] Support lifetime extension of temporary created by aggregate initialization using a default member initializer (PR #87933)

James Y Knight via cfe-commits cfe-commits at lists.llvm.org
Fri May 17 12:20:38 PDT 2024


jyknight wrote:

Here's a test case that clang diagnoses with `-Wundefined-inline` after this patch, which I'm not sure whether is correct or not. It might violate https://eel.is/c++draft/temp.inst#11 to attempt to instantiate the unused `S::operator int<int>`?

I'm having a hard time telling whether this code is ill-defined NDR, or if the compiler is required to accept this.

Clang stopped diagnosing this code with the fix for CWG2631, ca619613801233ef2def8c3cc7d311d5ed0033cb. Now this PR makes it diagnose again, despite that the default arg is never actually used.

```
struct S {
  template <typename T>
  consteval operator T();
};

struct M {
  int x = S();
};

void test(M m = {}) {}
```

```
test2.cc:3:13: error: inline function 'S::operator int<int>' is not defined [-Werror,-Wundefined-inline]
    3 |   consteval operator T();
      |             ^
test2.cc:7:11: note: used here
    7 |   int x = S();
      |           ^
1 error generated.
```

https://github.com/llvm/llvm-project/pull/87933


More information about the cfe-commits mailing list