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: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

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.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to