This sounds like a quiz question and is not presented by the student, but the professor is testing the publication on stackoverflow, but let him see ...
Let's start with the rule of definition. It is clear that no version violates this, so they both transmit this part.
Then, to the syntax. They also do not have syntax errors, they will compile without problems if you do not mind the possible combination of syntax and semantic problem.
Firstly, a simpler semantic problem. This is not a syntax issue, but f() , in both versions, is a member of the structure, and the function does not explicitly change its own structure, returning a constant. Although the function is declared as constexpr, it is not declared as const, which means that if there is any reason to call it a run-time function, it will generate an error if this attempt was made to const S. This affects both versions .
Now a potentially ambiguous return g(S()); Clearly, external g is a function call, but S may not be as clear as it would be if return g(S{}); were written return g(S{}); With {} initializing S, in the future there would be no ambiguity should struct S be extended using the () operator (the structure is almost like a functor). The called constructor is automatically generated now, and there is no operator () to create confusion for the compiler in this version, but modern C ++ 14 should offer clearer alternatives to avoid the "Most Vexing Parse", which is g (S ()).
So, I have to say that on the basis of semantic rules they both fail (not so bad though).
source share