[llvm-bugs] [Bug 45249] New: type traits considered non-constant in a constrained function template in a module.

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Mar 19 03:42:08 PDT 2020


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

            Bug ID: 45249
           Summary: type traits considered non-constant in a constrained
                    function template in a module.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C2x
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rbock at eudoxos.de
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

When used in a `requires` clause in a module, type traits are not considered
constexpr.

test.cpp
```
export module test;

import <type_traits>;

export template<typename T>
requires(std::is_integral_v<T>)
void do_something(const T&)
{
}

```
# clang++ -std=c++20 -stdlib=libc++ -fmodules -c -Xclang -emit-module-interface
-o test.pcm test.cpp

main.cpp
```
import test;

int main() {
    do_something(7);
}
```
# clang++ -std=c++20 -stdlib=libc++ -fmodules -fimplicit-modules
-fimplicit-module-maps -fprebuilt-module-path=. main.cpp

Output:
```
In file included from main.cpp:1:
test.cpp:6:10: error: substitution into constraint expression resulted in a
non-constant expression
requires(std::is_integral_v<T>)
         ^~~~~~~~~~~~~~~~~~~~~
main.cpp:4:5: note: while checking constraint satisfaction for template
'do_something<int>' required here
    do_something(7);
    ^~~~~~~~~~~~
main.cpp:4:5: note: in instantiation of function template specialization
'do_something<int>' requested here
test.cpp:6:10: note: subexpression not valid in a constant expression
requires(std::is_integral_v<T>)
         ^
main.cpp:4:5: error: no matching function for call to 'do_something'
    do_something(7);
    ^~~~~~~~~~~~
test.cpp:7:6: note: candidate template ignored: failed template argument
deduction
void do_something(const T&)
     ^
2 errors generated.
```

# clang++ --version
clang version 11.0.0 (https://github.com/llvm/llvm-project.git
70e4fb8a53984ff57b503cf13706c7e6683d650e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/clang-trunk/bin

-- 
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/20200319/363c9576/attachment-0001.html>


More information about the llvm-bugs mailing list