<div dir="ltr">Hi,<br><br>I was looking at bug 18275 - Incorrect const qualifier behavior in definition.<br><br>The declaration of A::f has a const. The definition doesn't.<br><br><i>template <typename T><br>struct A<br>
{<br> void f(const int);<br>};<br><br>template <typename T><br>void A<T>::f(int x)<br>{<br> x = 0;<br>}<br><br>void f()<br>{<br> A<float> a;<br> a.f(0);<br>}<br></i><br><br>Clang produces an error:<br>
<br>test.cpp:10:7: error: read-only variable is not assignable<br> x = 0;<br> ~ ^<br>test.cpp:26:7: note: in instantiation of member function 'A<float>::f'<br>requested here<br> a.f(0);<br> ^<br>
<br>It only happens for templateclasses. In exact the same situation with a regular class everything compiles well.<br><br><i>struct B<br>{<br> void f(const int);<br>};<br><br>void B::f(int x)<br>{<br> x = 0;<br>}<br>
<br>void f()<br>{<br> B b;<br> b.f(0);<br>}<br><br></i>GCC compiles both examples without an error.<br><br>According to my understanding, the standard 13.1/3 states that Parameter declarations that differ only in the presence or absence of const and/or volatile are equivalent. That is, the const and volatile type-specifiers for each parameter type are ignored when determining which function<br>
is being declared, defined, or called. So clang is wrong to throw error in template case.<br><br>After following the code path for above examples, i came across function name "<i>Sema::ActOnFunctionDeclarator</i>" in SemaDecl.cpp file, where everytime a function is redeclared/defined, its new declaration is created '<i>CreateNewFunctionDecl</i>', and its parameters are copied in following lines of code (l<i>ine number 6890 in SemaDecl.cpp in latest trunk version</i>)<br>
<br><i>for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i) {<br> ParmVarDecl *Param = cast<ParmVarDecl>(FTI.ArgInfo[i].Param);<br> assert(Param->getDeclContext() != NewFD && "Was set before ?");<br>
Param->setDeclContext(NewFD);<br> Params.push_back(Param);<br></i><br>I couldn't find exactly where the codepath gets different for above two cases. For both TC above, parameters get copied in above lines of code. Can someone help in pointing out, where does the properties of function parameters/variables are set and where does those properties get reset on redeclaration/definition? Am i going wrong somewhere in above code analysis?<br>
<br clear="all"><br>-- <br>With regards,<br>Suyog Sarda<br>
</div>