Community
Participate
Working Groups
Build Identifier: I20110512-2000 In the simple code below I would expect to have the copy constructor (of X) attached as an implicit name in the declarator node of "x2". This did not occur in version 7.0 but is observable on 8.0. ----------------- struct X { X(){} ~X(){} X(X const & x){} }; int main() { X x; X x2 = x; return 0; } ----------------- Conversion constructor works fine. I expect the problem in the following area: In CPPSemantics.findImplicitlyCalledConstructor() the call Conversions.checkImplicitConversionSequence(type, sourceType, isLValue, UDCMode.ALLOWED, Context.ORDINARY) for identical "type" and "sourceType" returns a "Cost" which returns "true" for "converts()" but does not provide "c.getUserDefinedConversion()". I'm not sure though whether it is generally correct to change the bevhavior there. I've attached an attempt for an easy workaround which prevents checking the conversion sequence by directly creating a "Cost" through "Conversions.copyInitializationOfClass()". While this satisfies the core unit tests, it does not work for copy construction of a derived class. ----------------- struct X { X(){} ~X(){} X(X const & x){} }; struct Y : X { }; int main() { Y y; X x = y; return 0; } ----------------- Probably Markus can find a better solution. :) Reproducible: Always
Created attachment 196764 [details] Patch: Workaround for identical types
Created attachment 196767 [details] Improved workaround capable of dealing with inheritance While the first patch was of quite limited use and had a probably incorrect equal-comparison, the second attempt works for inheritance structures as well.
(In reply to comment #2) > Created attachment 196767 [details] > Improved workaround capable of dealing with inheritance > While the first patch was of quite limited use and had a probably incorrect > equal-comparison, the second attempt works for inheritance structures as well. Thomas, thanks for reporting the issue. Your patch is a good fix for the problem.
Applied patch and added a test-case.