https://bugs.llvm.org/show_bug.cgi?id=50570
Bug ID: 50570
Summary: Clang either crashes or choose wrong destructor when
using multiple destructors using C++20 constraints
Product: clang
Version: trunk
Hardware: All
OS: All
Status: NEW
Severity: release blocker
Priority: P
Component: C++2a
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected],
[email protected], [email protected]
Created attachment 24905
--> https://bugs.llvm.org/attachment.cgi?id=24905&action=edit
1 of the program which i described above (also have links to godbolt)
Overview: When we use multiple destructor (1 default and 1 constraint 1) ,
using just a simple constraint, then 1 of 2 things happen:
A.) If we define the constraint destructor first, and then define default
destructor:
https://godbolt.org/z/PWbfzscs4
#include <iostream>
#include <concepts>
template <typename T>
concept hasReleaseMethod = requires(T t)
{
t.release();
};
template <typename T>
class ComWrapper
{
T t;
public:
~ComWrapper() requires requires(T t) { t.release(); }
{
std::cout << "destructor";
t.release();
}
~ComWrapper() = default;
};
struct hasRelease
{
int a = 23;
void release()
{
std::cout << "in release method:\n"
<< a;
}
void method()
{
}
};
struct notHadRelease
{
};
int main()
{
ComWrapper<hasRelease> Ob;
ComWrapper<notHadRelease> ob2;
};
Actual result: the compiler crashed (you can see the error through the cooler l
compiler explorer (godbolt)).
Expected result: the clang should choose the constraint destructor on ob1
(hasRelease) and default destructor on ob2. The GCC produce the expected output
The program works on GCC and didn't work on clang, where we declared the
constraint destructor first and then default destructor (GCC compiler &
executor on the upper window and Clang on the lower)
https://godbolt.org/z/PWbfzscs4
You can check on godbolt through the above link
B.) When we declared the default destructor first, & then the constraint
destructor
//The program is same as above except the default destructor is declared first
#include <iostream>
#include <concepts>
template <typename T>
concept hasReleaseMethod = requires(T t)
{
t.release();
};
template <typename T>
class ComWrapper
{
T t;
public:
~ComWrapper() = default;
~ComWrapper() requires requires(T t) { t.release(); }
{
std::cout << "destructor";
t.release();
}
};
struct hasRelease
{
int a = 23;
void release()
{
std::cout << "in release method:\n"
<< a;
}
void method()
{
}
};
struct notHadRelease
{
};
int main()
{
ComWrapper<hasRelease> Ob;
ComWrapper<notHadRelease> ob2;
};
https://godbolt.org/z/ss11d5cdd
When we declared the default destructor first, & then the constraint destructor
, the Clang compiles, but the default destructor is called & the constraint
destructor is discarded every time(see the executor and assembly in clang).
Whereas, GCC executes correctly.
--
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