[llvm-bugs] [Bug 47350] New: Consteval functions in unevaluted context

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Aug 29 04:12:21 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47350

            Bug ID: 47350
           Summary: Consteval functions in unevaluted context
           Product: clang
           Version: 11.0
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dudkindaniilm2 at yandex.ru
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Created attachment 23903
  --> https://bugs.llvm.org/attachment.cgi?id=23903&action=edit
The code

The problem is reproducible with clang 11 and clang trunk

Code:

struct N {
  constexpr N() {}
  N(N const&) = delete;
};
template <typename T> constexpr void bad_assert_copyable() { T t; T t2 = t; }
using ineffective = decltype(bad_assert_copyable<N>());

template <typename T> consteval void assert_copyable() { T t; T t2 = t; }
using check = decltype(assert_copyable<N>());

int main() {}

Link 1. https://godbolt.org/z/j9TTed
Link 2. https://wandbox.org/permlink/jYwoQg7pKd4mMMwv

Before P1937R2 were merged into C++20 draft it really was an illegal code
because in unevaluted context consteval function must be evaluted. But now it's
totally legal code.

Link 3. P1937R2:
http://open-std.org/JTC1/SC22/WG21/docs/papers/2020/p1937r2.html

Local compile using clang build from LLVM 11.0.0-rc2:

$ ./clang++ -v
clang version 11.0.0 (https://github.com/llvm/llvm-project.git
0160ad802e899c2922bc9b29564080c22eb0908c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /mnt/c/clang+llvm-11.0.0-rc2-x86_64-linux-gnu-ubuntu-20.04/bin/.
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Candidate multilib: .;@m64
Selected multilib: .;@m64

$ ./clang++ test/bug.cpp -std=c++2a
test/bug.cpp:10:24: error: call to consteval function 'assert_copyable<N>' is
not a constant expression
using check = decltype(assert_copyable<N>());
                       ^
test/bug.cpp:10:24: note: undefined function 'assert_copyable<N>' cannot be
used in a constant expression
test/bug.cpp:9:37: note: declared here
template<typename T> consteval void assert_copyable() { T t; T t2 = t; }
                                    ^
1 error 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/20200829/ead0b713/attachment-0001.html>


More information about the llvm-bugs mailing list