Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 407497 - false positive for 'invalid template arguments' when using nested templates.
Summary: false positive for 'invalid template arguments' when using nested templates.
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-codan (show other bugs)
Version: 8.1.1   Edit
Hardware: All All
: P3 minor (vote)
Target Milestone: 8.2.1   Edit
Assignee: Nathan Ridge CLA
QA Contact: Elena Laskavaia CLA
URL:
Whiteboard:
Keywords:
: 407496 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-05-08 03:49 EDT by jdavid luque CLA
Modified: 2013-08-31 01:52 EDT (History)
3 users (show)

See Also:


Attachments
example of the issue (765 bytes, text/x-csrc)
2013-05-08 03:49 EDT, jdavid luque CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description jdavid luque CLA 2013-05-08 03:49:28 EDT
Created attachment 230631 [details]
example of the issue

I am using nested template with member pointers List<N>::Base<&N::node_member>, this compiles ok, but codecan report 'invalid template arguments'.
Comment 1 Nathan Ridge CLA 2013-07-08 23:09:28 EDT
Reduced example:


struct N 
{
    int node;
};
 
template <typename T>
struct List 
{
    template <int T::*>
    struct Base {};
};

List<N>::Base<&N::node> base; // ERROR: Invalid template argument
Comment 2 Andrew Gvozdev CLA 2013-07-09 09:13:02 EDT
*** Bug 407496 has been marked as a duplicate of this bug. ***
Comment 3 Nathan Ridge CLA 2013-07-09 21:48:38 EDT
The problem is that when specializing List<T>::Base to be List<N>::Base, the substitution T = N is not performed on the T in Base's template parameter.
Comment 4 Nathan Ridge CLA 2013-07-09 22:42:22 EDT
(In reply to comment #3)
> The problem is that when specializing List<T>::Base to be List<N>::Base, the
> substitution T = N is not performed on the T in Base's template parameter.

Unfortunately, fixing this is not as easy as I hoped. Unlike a template argument, which is just a thin wrapper for a type or an evaluation, a template parameter is a binding, and conceptually, subtituting template arguments within one yields a new, specialized binding. I think we will have to introduce new binding types for template parameter specializations.
Comment 5 Nathan Ridge CLA 2013-07-09 23:35:57 EDT
See also bug 399454, where a similar problem occurs, but with the nested template's template parameter's default value rather its type.
Comment 6 Nathan Ridge CLA 2013-07-13 20:02:25 EDT
Patch (also fixes bug 399454): https://git.eclipse.org/r/#/c/14533/
Comment 7 Nathan Ridge CLA 2013-07-16 01:03:59 EDT
Updated patch to fix a bug in EvalTypeId.unmarshal() that caused an NPE (the bug had always been there, but the changes in this patch exposed it).
Comment 8 CDT Genie CLA 2013-07-21 23:22:06 EDT
*** cdt git genie on behalf of Nathan Ridge ***

    Bug 407497, Bug 399454 - Specialize template parameters when appropriate
    Change-Id: Iff52b04319234ca8e5fe0f9b23d5d1787cee4449
    Signed-off-by: Nathan Ridge &lt;zeratul976@xxxxxxxxxxx&gt;
    Reviewed-on: <a  href="https://git.eclipse.org/r/14533">https://git.eclipse.org/r/14533</a>
    Reviewed-by: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;
    IP-Clean: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;
    Tested-by: Sergey Prigogin &lt;eclipse.sprigogin@xxxxxxxxx&gt;

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=2050fe2bfb91b213a99f00033f19a11a90b903c9
Comment 9 Marc-André Laperle CLA 2013-07-23 00:02:41 EDT
Fixed in 8.2.1 and master.
Comment 10 Marc-André Laperle CLA 2013-08-31 01:52:59 EDT
(In reply to Nathan Ridge from comment #1)
> Reduced example:
> 
> 
> struct N 
> {
>     int node;
> };
>  
> template <typename T>
> struct List 
> {
>     template <int T::*>
>     struct Base {};
> };
> 
> List<N>::Base<&N::node> base; // ERROR: Invalid template argument

This is giving me a "Unsafe method call. Instantiation of dependent expressions may not work", see bug 416284.
Using 8.2.1 RC1 (EPP 20130821-2252).