[cfe-dev] Clang: template functions

Frits van Bommel fvbommel at gmail.com
Fri Nov 5 04:11:42 PDT 2010


On Fri, Nov 5, 2010 at 11:53 AM, Stefano S <kindoblue at gmail.com> wrote:
> For the first time I built llvm + clang on ubuntu box for giving it a try.
> I have this simple template function in a header file
> template <typename T, typename U>
> inline void SetMin(T &aVar,U aValue);
> but clang++ returns
> ../src/myfile.h:13:1: error: unknown type name 'template'
> template <typename T, typename U>
> ^
> ../src/myfile.h:13:10: error: expected identifier or '('
> template <typename T, typename U>

Are you sure you're using clang++? I get the same error when I use
"clang -c test.h", but when I use "clang++ -c test.h" it compiles the
header just fine (though it does warn about treating a 'c-header' as
'c++-header' in C++ mode).

> I tried to use also -std=gnu89 because I've read gcc (which compiles my
> code) uses that standard by default, but with no success.

-std=gnu89 turns on GNU C mode, not GNU C++ mode. Try -std=c++98 or
-std=gnu++98 if you're using clang instead of clang++.



More information about the cfe-dev mailing list