[cfe-dev] Clang 3.2 error or incorrect code ?

Matthieu Monrocq matthieu.monrocq at gmail.com
Fri Jan 18 10:02:02 PST 2013


Thanks Richard!

I had not considered the ambiguity and I understand much better why the
compiler diagnosis were so off the bat: now it makes sense that it would
try to use N as a type and complain.

The suggested work-around (parentheses) works like a charm.

-- Matthieu

On Fri, Jan 18, 2013 at 6:45 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> See PR13657
> On 18 Jan 2013 08:37, "Matthieu Monrocq" <matthieu.monrocq at gmail.com>
> wrote:
>
>> The snippet below is successfully compiled by gcc 4.7.2:
>>
>> template <typename T, unsigned N>struct Helper {};
>> template <typename T, unsigned N >Helper< T, N > GetHelper() { return Helper< T, N > (); }
>> template < typename T, unsigned N >struct X {
>>     X( Helper< T, N > h = GetHelper<T, N>() ) {}};
>>
>> With clang 3.2 though it spews a lot of errors:
>>
>> Compilation finished with errors:
>> source.cpp:9:40: error: unknown type name 'N'
>> X( Helper< T, N > h = GetHelper<T, N>() ) {}
>> ^
>> source.cpp:9:41: error: expected ')'
>> X( Helper< T, N > h = GetHelper<T, N>() ) {}
>> ^
>> source.cpp:9:6: note: to match this '('
>> X( Helper< T, N > h = GetHelper<T, N>() ) {}
>> ^
>> source.cpp:9:38: error: expected '>'
>> X( Helper< T, N > h = GetHelper<T, N>() ) {}
>> ^
>> 3 errors generated.
>>
>> for the exact position of the carets, you can see:
>> http://liveworkspace.org/code/3EALA5$27
>>
>> - the first caret is positionned under the N of GetHelper<T, N>()
>> - the second caret is positionned under the > of GetHelper<T, N>()
>> - the fourth caret is positionned under the comma of GetHelper<T, N>()
>>
>> I suspect a clang bug, given that gcc manages to compile the code.
>>
>> Note: related SO question => http://stackoverflow.com/q/14401308/147192
>>
>> -- Matthieu
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130118/1194ad10/attachment.html>


More information about the cfe-dev mailing list