1

I came to know that the C++ standard doesn't define the term user-declared constructor but it uses that term at many places. Now to my current understanding, the term user-declared constructor is self explanatory.

But one user disagrees with my above understanding as they say:

It's not entirely self explanatory. The place things get tricky is with special member functions of things in the standard library. Even though a normal user never writes the code for constructors of things like std::string, I believe those still fall within the realm of "user declared" special member functions--but I can't quote anything from the standard to back that up, and there are fair arguments to be made that they're not.


So my question is that should the term user-declared constructors be defined by the standard? That is, is there any example where there is some ambiguity due to the term as said by the above quoted comment or is the term self-explanatory.

My current understanding is that user-declared in this context means "written by the user". That is, "which is not implicitly synthesized".

Kal
  • 475
  • 1
  • 16
  • "user declared" doesn't mean that I personally have to declare it, someone else could have. Like a library author, including for the standard library. – BoP Sep 06 '22 at 16:54
  • @BoP Yes ofcourse I know that. I never said that " I personally have to declare it". Instead I mean that it is "written by the user whoever that user may be" and as long as it is not implicitly synthesized by the compiler. – Kal Sep 06 '22 at 17:06
  • I'm voting to close as opinion-based. Perhaps this is something that should be improved in the standard, but IMO the standard mailing list is a better place to have such discussions rather than stackoverflow. – Miles Budnek Sep 06 '22 at 17:19
  • @Kal - So where is the confusion? If the standard were to define "user-declared constructors" as "constructors declared by the user", would that improve anything? Is there a better definition? – BoP Sep 06 '22 at 17:42
  • @BoP I think the OP asked the question because the user [Jerry Coffin](https://stackoverflow.com/questions/73624520/whats-the-definition-of-user-declared-constructor-in-the-c-standard#comment130012905_73624520) was claiming that the term is not self explanatory. Note also that i do think that the term is self explanatory as also said in my previous [comments](https://stackoverflow.com/questions/73624520/whats-the-definition-of-user-declared-constructor-in-the-c-standard#comment130012882_73624520) in the same thread. – Jason Sep 06 '22 at 17:46
  • @BoP Also the same user [said](https://stackoverflow.com/questions/73624520/whats-the-definition-of-user-declared-constructor-in-the-c-standard#comment130013030_73624520): *"In fact, I've talked with a committee member about this who agreed it was ambiguous and should be defined (but was busy with enough other things he wasn't willing to delay them to work on this)"* – Jason Sep 06 '22 at 17:48
  • Does this answer your question? [C++ Rule of Zero & what is "user-declared" constructor?](https://stackoverflow.com/questions/40959659/c-rule-of-zero-what-is-user-declared-constructor) – Quuxplusone Sep 06 '22 at 21:54
  • 1
    Yes, "user-declared" is the opposite of "implicitly declared"; see https://stackoverflow.com/questions/40959659/c-rule-of-zero-what-is-user-declared-constructor . The rest of this question seems off-topic for SO. (But IMHO it might be reasonable to open a CWG issue and request adding a definition for "user-declared function" in the Terms and Definitions section, alongside ["program-defined type"](https://eel.is/c++draft/defns.prog.def.type).) – Quuxplusone Sep 06 '22 at 21:59

1 Answers1

1

This is CWG2632 and the potential ambiguity(if any) will be resolved by adding the resolution given there:

user-declared [defns.user.declared]

declared in a translation unit using a declarator-id

[ Note 1 to entry: In contrast, some special member functions can be implicitly declared by the implementation. -- end note]

Jason
  • 36,170
  • 5
  • 26
  • 60