<HTML><HEAD><TITLE>Samsung Enterprise Portal mySingle</TITLE>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type>
<STYLE id=mysingle_style type=text/css>P {
        MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
TD {
        MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
LI {
        MARGIN-BOTTOM: 5px; FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN-TOP: 5px
}
BODY {
        FONT-SIZE: 9pt; FONT-FAMILY: Arial, arial; MARGIN: 10px; LINE-HEIGHT: 1.4
}
</STYLE>

<META content=IE=5 http-equiv=X-UA-Compatible>
<META name=GENERATOR content=ActiveSquare></HEAD>
<BODY>
<P>Hi all,<BR>This is regarding this program<BR><BR>#include <string><BR>#include <iostream></P>
<P>struct A {<BR>  A(){};<BR>  A(const A &) { std::cout << "A's Copy Constructor" << std::endl; }<BR>};</P>
<P>struct B : A<BR>{<BR>  B(int) { std::cout << "Constructor" << std::endl; }<BR>  B(const B &) { std::cout << "Copy Constructor" << std::endl; }<BR>  B(A) { std::cout << "Special Constructor" << std::endl; }<BR>};</P>
<P>void foo(B){}</P>
<P>int main()<BR>{<BR>  foo(0);<BR>  return 0;<BR>}</P><!--SP:chakshu.gro--><!--chakshu.gro:EP-->
<P> </P>
<P>The output of this program is<BR></P>
<P>Constructor</P>
<P> </P>
<P>using both gcc and clang<BR><BR>But if the program is slightly different ("const" missing from B's copy constructor) <BR><BR>#include <string><BR>#include <iostream></P>
<P>struct A {<BR>  A(){};<BR>  A(const A &) { std::cout << "A's Copy Constructor" << std::endl; }<BR>};</P>
<P>struct B : A<BR>{<BR>  B(int) { std::cout << "Constructor" << std::endl; }<BR>  B(B &) { std::cout << "Copy Constructor" << std::endl; }<BR>  B(A) { std::cout << "Special Constructor" << std::endl; }<BR>};</P>
<P>void foo(B){}</P>
<P>int main()<BR>{<BR>  foo(0);<BR>  return 0;<BR>}<BR><BR>Output of gcc is<BR></P>
<P>Constructor</P>
<P>A's Copy Constructor</P>
<P>Special Constructor</P>
<P><BR>Clang doesn't compile giving error </P>
<P>"no viable constructor copying parameter of type 'B' "<BR><BR>My previous understanding was that gcc tried to use B's copy constructor but as it has non constant reference argument so it uses A's copy constructor but even after adding the "const", I see that "Copy Constructor" is still not printed.<BR>Clang is unable to compile that means it is not even trying to do it using B(A) constructor when const is not present. When it is, then also "Copy Constructor" is not printed.<BR><BR>Please suggest where I might be wrong and why I am observing this behavior.<BR>Any leads will be helpful<BR><BR>Regards,<BR>Chakshu</P>
<TABLE id=confidentialsignimg>
<TBODY>
<TR>
<TD NAMO_LOCK>
<P><IMG border=0 src="cid:4CBBEM6S04A2@namo.co.kr"></P></TD></TR></TBODY></TABLE></BODY></HTML><img src='http://ext.samsung.net/mailcheck/SeenTimeChecker?do=fe69aed3ab8a86cab546ee734f6ade8e3cf926662d15d74741c8c4d357c4447bc400edea8930898a434c6ebf74e200ff220d3e02ce1cb961d6250c6ef56fc7aacf878f9a26ce15a0' border=0 width=0 height=0 style='display:none'>