[llvm-bugs] [Bug 51078] New: consteval function inside of class template cannot use template type parameters in some contexts
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jul 13 08:41:20 PDT 2021
https://bugs.llvm.org/show_bug.cgi?id=51078
Bug ID: 51078
Summary: consteval function inside of class template cannot use
template type parameters in some contexts
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++2a
Assignee: unassignedclangbugs at nondot.org
Reporter: evanacox.dev at gmail.com
CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
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: https://godbolt.org/z/hx97WTjG3
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210713/175ae461/attachment.html>
More information about the llvm-bugs
mailing list