http://llvm.org/bugs/show_bug.cgi?id=9049

           Summary: type-dependent attribute evaluated during template
                    definition
           Product: clang
           Version: trunk
          Platform: Macintosh
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]


Created an attachment (id=6045)
 --> (http://llvm.org/bugs/attachment.cgi?id=6045)
Simple test case

When using type dependent 'attribute' on a template function, clang checks the
type while parsing the template, and not at instantiation, and so may emit
invalid diagnostics.

For example, in the following case, we are using the 'cf_returns_retained'
attribute, which require a pointer return type. As the type is undefined in
template definition, the check fails, and clang emits a warning.

----------- attr.cpp

extern const void *CFRetain(const void *ref);

template<typename T> __attribute__((cf_returns_retained))
inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }

------------

> clang++ -fsyntax-only attr.cpp
attr.cpp:5:10: warning: 'cf_returns_retained' attribute only applies to
functions that return a pointer
inline T WBCFRetain(T aValue) { return aValue ? (T)CFRetain(aValue) : (T)0; }
         ^
1 warning generated.


Note that this problem also occurs if you use attributes on a type-dependent
arguments.

----------- attr.cpp

extern void CFRelease(const void *ref);

template<typename T>
inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue)
CFRelease(aValue); }

-----------
> clang++ -fsyntax-only attr.cpp
attr.cpp:5:54: warning: 'cf_consumed' attribute only applies to pointer
parameters
inline void WBCFRelease(__attribute__((cf_consumed)) T aValue) { if(aValue)
CFRelease(aValue); }
                                       ~~~~~~~~~~~   ^

-- 
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.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to