Hi Richard,
As per your comments, I am now comparing return type from type source info.
By this way we are able to catch hold of ’ auto ’ as return type of declared function.
If the return types from type source info do not match, then error is emitted.
I am doing this only for auto types, as there can be return type of template
parameter of the declared template (in which, we do not compare as template parameter can equal actual return type).
Patch Code highlight:
TypeSourceInfo *TI = Function->getTypeSourceInfo();
QualType FuncReturnType = TI->getType()->castAs()->getReturnType();
if (isa(ArgFunctionType)){
QualType ArgFunctionReturnType = ArgFunctionType->getAs()->getReturnType();
// We check for auto contained type to eliminate checking template parameter as return type
if (FuncReturnType->getContainedAutoType()){
if (!Context.hasSameType(ArgFunctionReturnType,FuncReturnType))
return TDK_MiscellaneousDeductionFailure;
else
return TDK_Success;
}
}
Bug 19551 gets resolved with this patch.
Test case :
template auto f(T) { return 0; }
int k = f(0); // #1
template auto f(int); // #2
template int f(int); // #3
Output with patch :
suyog@suyog-Inspiron-N5010:~$ llvm/llvm/build/bin/clang bug_19551.C -std=c++1y
bug_19551.C:4:14: error: explicit instantiation of ‘f’ does not refer to a function template, variable template, member function, member class,
or static data member
template int f(int); // #3
^
bug_19551.C:1:27: note: candidate template ignored: failed template argument deduction
template auto f(T) { return 0; }
^
1 error generated.
This patch also differentiates between ’ auto ’ and ’ auto* ’ and throws error for such case too.
However, I am getting 1 regression in file test/SemaCXX/cxx1y-deduced-return-type.cpp.
It contains cases where return types are same and we also need to check if Specialization type
matches with ArgFunction Type - which is exactly opposite to our test case
(Specialization type doesn’t match with ArgFunction Type in our test case 19551). Its like trying to validate true and false
at the same time.
I am attaching patch for the reference. (test case excluded for a while).
Your comment will be a great help to resolve this. Thanks !
19551.patch (2.89 KB)