<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - consteval function inside of class template cannot use template type parameters in some contexts"
href="https://bugs.llvm.org/show_bug.cgi?id=51078">51078</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>consteval function inside of class template cannot use template type parameters in some contexts
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++2a
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>evanacox.dev@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Problem is reproducible in Clang 12.0.0 and Clang trunk.
Clang seems to not be able to deal with consteval functions that use type
parameters,
but only in specific contexts.
Code:
template <typename T> struct Foo {
static consteval unsigned long foo() {
return sizeof(T);
}
static consteval auto bar() {
return sizeof(T);
}
static consteval T baz() {
return T();
}
void f() {
constexpr auto result = foo();
}
void g() {
// different error from `foo()`?
constexpr auto result = bar();
}
void h() {
constexpr auto result = baz();
}
// all of these work fine
int array1[foo()];
int array2[bar()];
int array3[baz()];
};
Clang Trunk: <a href="https://godbolt.org/z/hx97WTjG3">https://godbolt.org/z/hx97WTjG3</a>
Local Compile:
$ clang++ -v
clang version 12.0.0 (Fedora 12.0.0-2.fc34)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation:
/usr/bin/../lib/gcc/x86_64-redhat-linux/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/11
Selected GCC installation: /usr/lib/gcc/x86_64-redhat-linux/11
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
$ clang++ -std=c++20 ./bug.cc
./bug.cc:15:29: error: call to consteval function 'Foo::foo' is not a
constant expression
constexpr auto result = foo();
^
./bug.cc:20:29: error: cannot take address of consteval function 'bar'
outside of an immediate invocation
constexpr auto result = bar();
^
./bug.cc:6:25: note: declared here
static consteval auto bar() {
^
./bug.cc:24:29: error: cannot take address of consteval function 'baz'
outside of an immediate invocation
constexpr auto result = baz();
^
./bug.cc:10:22: note: declared here
static consteval T baz() {
^
3 errors generated.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>