llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[Clang] Rejects valid `void_t<>{}`

Open MagentaTreehouse opened this issue 2 months ago • 3 comments

template <class...>
using void_t = void;

template <class T>
void f(T) {
    ::void_t<>{};
}

void g() {
    f(0);
}

See https://compiler-explorer.com/z/E7aGq4dqY.

Output:

<source>:6:5: error: cannot initialize non-class type '::void_t<>' (aka 'void') with a parenthesized initializer list
    6 |     ::void_t<>{};
      |     ^         ~~
<source>:10:5: note: in instantiation of function template specialization 'f<int>' requested here
   10 |     f(0);
      |     ^
1 error generated.

MagentaTreehouse avatar Sep 25 '26 13:09 MagentaTreehouse

@llvm/issue-subscribers-clang-frontend

Author: MagentaTreehouse

```c++ template <class...> using void_t = void;

template <class T> void f(T) { ::void_t<>{}; }

void g() { f(0); }


See https://compiler-explorer.com/z/E7aGq4dqY.

Output:
```console
&lt;source&gt;:6:5: error: cannot initialize non-class type '::void_t&lt;&gt;' (aka 'void') with a parenthesized initializer list
    6 |     ::void_t&lt;&gt;{};
      |     ^         ~~
&lt;source&gt;:10:5: note: in instantiation of function template specialization 'f&lt;int&gt;' requested here
   10 |     f(0);
      |     ^
1 error generated.

The alias isn't needed, also happens with

template <class T>
void f(T) {
    void{};
}

seems to be a missed case from https://github.com/llvm/llvm-project/pull/78060 when the expression is non-dependent in an instantiation.

keinflue avatar Sep 25 '26 14:09 keinflue

Thanks for the report! I opened #228340 to fix the issue.

IvyXu420 avatar Oct 02 '26 06:10 IvyXu420