1

Is there a way to actually see (output to file, console etc) implicit compiler generated or = default methods (in C++)?

(Target compilers: vc, clang, gcc)

I'd like to see how these functions are actually implemented. For example, how does the assignment operator assigns its values, does it check for self assignment, is const correctness given etc). I did not found any statisfying result on the www that actually shows the implementations of these compiler generated functions.

Buni
  • 251
  • 2
  • 13
  • No. But it is simple to write one. Just do the operation on every member. – M.M Jul 15 '14 at 08:53
  • 3
    Only as intermediate code (if the compiler supports to emit the intermediate code) or as assembly code. But generally the default constructor will be just empty. – Some programmer dude Jul 15 '14 at 08:53
  • Is the question, what does the compiler output, i.e. the generated code? – Niall Jul 15 '14 at 08:54
  • A `C++` output would be optimal – Buni Jul 15 '14 at 08:55
  • @JoachimPileborg "generally the default constructor will be just empty" - it's common enough to have data members (directly or indirectly) like `std::string`s, `vector`s, smart pointers etc. that I'd question the "generally" there.... – Tony Delroy Jul 15 '14 at 08:57
  • 5
    The semantics of defaulted special members are clearly defined in the Standard. It's essentially member-wise application of the operation plus an empty body. – Kerrek SB Jul 15 '14 at 08:57
  • @Benu: it might be "optimal" from your perspective, but experienced programmers know what to expect of these functions anyway and the compiler writers have better things to do (like achieve full C++11 Standard compliance, continue on to C++14).... – Tony Delroy Jul 15 '14 at 08:58

1 Answers1

1

The semantics of the "special member" functions are defined by the C++ standard, in section 12

In brief, they do what you think they do;

  • The default will invoke the defaults of the bases and the members
  • The copy will invoke the copy of the bases and members
  • The same applies for the moves, assignments and destructor

If, for some reason, one of them would violate a const correctness or the corresponding constructor or assignment of the base or members is not available, or some other issue arrises, then that special member is not declared.

An an additional note; there are specific rules that apply to the defaults if one (or some) of the special members are defined by the user (detailed here).

Community
  • 1
  • 1
Niall
  • 30,036
  • 10
  • 99
  • 142