-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CWG1808 [class.prop] Templated default constructors should not be considered for eligibility #185
Comments
The standard library type namespace std::ranges {
struct dangling {
constexpr dangling() noexcept = default;
constexpr dangling(auto&&...) noexcept {}
};
} GCC thinks it's trivial, but Clang (and some new versions of MSVC) doesn't. Per the current specification it's non-trivial, but this seems unintended. Ping @jensmaurer. |
It seems CWG1808 squarely covers this; see in particular the comment from Feb 2014, including the consideration to simply ditch the concept of "trivial class". (I'm not finding a use of "trivial class" outside of examples.) Which leads me to the question how you observe the property "trivial class" with a conforming program. You said above your example is considered trivial by gcc, but how do you query that? I also note that, strictly speaking, a constructor template is not a constructor (a function template is not a function), thus the phrasing "has one or more eligible default constructors" excludes constructor templates. |
It seems that the property itself only affects the results of There's an article (Trivial, but not trivially default constructible by @Quuxplusone) showing that just being a trivial class doesn't mean the class is trivially default constructible. |
It seems odd that other kinds of SMFs are invariably required to be non-templates: I know no reason to mourn if If There is implementation divergence on
According to the letter of the law, I think Related to Roy's test cases, but much simpler, every vendor seems to miscompile the following case according to the letter of the law. The wording says: "If there is no user-declared constructor for class X, a non-explicit constructor having no parameters is implicitly declared as defaulted"—
|
As discussed in #150, this example is ill-formed, no diagnostic required. So both rejection and acceptance are OK.
This is CWG2871. |
Bleh. OK. :) |
Full name of submitter: Roy Jacobson
Reference (section label): class.prop
Clang bug report: llvm/llvm-project#59206
Issue description:
A class may have a default constructor that is a template while also having a trivial default constructor. The function template default constructor should not prevent the class from being trivial only because it is more constrained.
Consider those classes:
Are those classes trivial? GCC and MSVC think they are, while class.prop says only A is trivial.
As far as I understand it, class
C
accidentally became non trivial with the resolution of DR1363 but no one actually implemented this.(Humbly) suggested resolution:
I like it because it preserves the notion of eligibility. I think making function templates just ineligible achieves the same effect and is an alternative solution.
Also somewhat related to CWG issue 1808.
The text was updated successfully, but these errors were encountered: