[LLVMbugs] [Bug 12167] New: template instantiation of single-element braced casts drops the cast
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Mar 2 14:29:49 PST 2012
http://llvm.org/bugs/show_bug.cgi?id=12167
Bug #: 12167
Summary: template instantiation of single-element braced casts
drops the cast
Product: clang
Version: unspecified
Platform: PC
OS/Version: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: C++0x
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: richard-llvm at metafoo.co.uk
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu,
sebastian.redl at getdesigned.at
Classification: Unclassified
Clang rejects this:
template<int N> struct string {};
struct X {
X(const char v);
template<typename T> bool operator()(T) const;
};
template<int N, class Comparator> bool g(const string<N>& s, Comparator f) {
return f(s); }
template<int N> bool f(const string<N> &s) { return g(s, X{'x'}); }
bool s = f(string<1>());
Errors:
tmp.cpp:11:10: error: called object type 'int' is not a function or function
pointer
return f(s);
^
tmp.cpp:16:10: note: in instantiation of function template specialization 'g<1,
char>' requested here
return g(s, X{'x'});
^
tmp.cpp:19:10: note: in instantiation of function template specialization
'f<1>' requested here
bool s = f(string<1>());
^
Note that we instantiate 'g<1, char>' not 'g<1, X>'. The body of the f template
looks like this:
(CompoundStmt 0x4df4160 <tmp.cpp:9:44, col:67>
(ReturnStmt 0x4df4140 <col:46, col:64>
(CallExpr 0x4df4108 <col:53, col:64> '<dependent type>'
(UnresolvedLookupExpr 0x4df3af0 <col:53> '<overloaded function type>'
lvalue (ADL) = '1' 0x4df14d0)
(DeclRefExpr 0x4df3b48 <col:55> 'const string<N>' lvalue ParmVar
0x4df3900 's' 'const string<N> &')
(CXXConstructExpr 0x4df3f80 <col:58, col:60> 'struct X''void (const
char)'
(CharacterLiteral 0x4df3b80 <col:60> 'char' 120)))))
... but it instantiates to this ...
(CompoundStmt 0x4df6288 <tmp.cpp:9:44, col:67>
(ReturnStmt 0x4df6268 <col:46, col:64>
(CallExpr 0x4df6230 <col:53, col:64> '_Bool'
(ImplicitCastExpr 0x4df6218 <col:53> '_Bool (*)(const string<1> &, char)'
<FunctionToPointerDecay>
(DeclRefExpr 0x4df6190 <col:53> '_Bool (const string<1> &, char)'
lvalue Function 0x4df6050 'g' '_Bool (const string<1> &, char)'
(FunctionTemplate 0x4df14d0 'g')))
(DeclRefExpr 0x4df5cb8 <col:55> 'const string<1>':'const struct
string<1>' lvalue ParmVar 0x4df5950 's' 'const string<1> &')
(CharacterLiteral 0x4df3b80 <col:60> 'char' 120))))
The CXXConstructExpr has *gone*. TreeTransform.h says:
// CXXConstructExprs are always implicit, so when we have a
// 1-argument construction we just transform that argument.
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list