Issue 146246
Summary [clang] constraints on constructors appear to be evaluated on class synthesis rather than on use
Labels c++
Assignees
Reporter ojhunt
    I was confused about what was happening with https://discourse.llvm.org/t/detect-if-type-is-complete-not-forward-decl/87107

It looks like we're trying to evaluate `requires` constraints on constructor methods during class synthesis rather than on use of the constructor, but I believe evaluation of these constraints should not occur until synthesis of the constructor.

https://godbolt.org/z/eM5dx99sY

```c++
#include <type_traits>

struct Dummy;
template<class T> struct MyTemplate {
	T*p;
	MyTemplate() 
		requires (std::is_default_constructible_v<T>)
		{ }
};

class MyTest {
	MyTemplate<struct Dummy> data;
public:
	MyTest();
	void someFn() { }
};

MyTest test;

int main() {
	test.someFn();
}

struct Dummy { int a; };
MyTest::MyTest() { }
```

This happens for all the constructors, even those that are not used - a minor modification: https://godbolt.org/z/YTK9c6adj - shows that the requires clause is evaluated for all constructors, even those that are not used in the TU:

```c++
#include <type_traits>

struct Dummy;
template<class T> struct MyTemplate {
	T*p;
    MyTemplate();
	MyTemplate(float f) 
		requires (std::is_default_constructible_v<T>)
		{ }
};

class MyTest {
	MyTemplate<struct Dummy> data;
public:
	MyTest();
	void someFn() { }
};

MyTest test;

int main() {
	test.someFn();
}

struct Dummy {  int a; };
MyTest::MyTest() { }
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to