llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.07k stars 11.99k forks source link

Error on requires expression in templated generic lambda #115802

Open Eczbek opened 1 day ago

Eczbek commented 1 day ago

https://godbolt.org/z/Yfb8dxYbj

int main() {
    []<int = 0> {
        void(requires(int* x) { x = 1; });
    }();
}
<source>:3:31: error: incompatible integer to pointer conversion assigning to 'int *' from 'int'
    3 |                 void(requires(int* x) { x = 1; });
      |                                             ^
1 error generated.
Compiler returned: 1

GCC and MSVC seem to be fine with this code.

llvmbot commented 1 day ago

@llvm/issue-subscribers-clang-frontend

Author: None (Eczbek)

https://godbolt.org/z/Yfb8dxYbj ```cpp int main() { []<int = 0> { void(requires(int* x) { x = 1; }); }(); } ``` ``` <source>:3:31: error: incompatible integer to pointer conversion assigning to 'int *' from 'int' 3 | void(requires(int* x) { x = 1; }); | ^ 1 error generated. Compiler returned: 1 ``` GCC and MSVC seem to be fine with this code.
zyn0217 commented 1 day ago

So if we remove the lambda, all three compilers will admit it's invalid.

https://godbolt.org/z/frdhjcbjT

Eczbek commented 1 day ago

I have just been informed that this might be IFNDR according to https://eel.is/c++draft/temp.res.general#6 and https://eel.is/c++draft/expr.prim.req.general#5.sentence-6