Bug 19407 - vector keyword in typedef inside template struct ignored
Summary: vector keyword in typedef inside template struct ignored
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 4.3.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid, wrong-code
Depends on: 17743
Blocks:
  Show dependency treegraph
 
Reported: 2005-01-12 21:26 UTC by Mike LeBlanc
Modified: 2007-09-24 10:46 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail:
Last reconfirmed: 2007-09-22 15:02:03


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike LeBlanc 2005-01-12 21:26:30 UTC
 
Comment 1 Mike LeBlanc 2005-01-12 21:29:47 UTC
The program below prints 4-s instead of 16-s.

     1  #include <stdio.h>
     2  #include <altivec.h>
     3
     4  template < typename Val > struct S {
     5      typedef vector Val vector_type;
     6      void pr_size() { printf ("size = %d\n", sizeof(vector_type)); }
     7      };  
     8
     9  int main()
    10  {
    11    printf ("size = %d\n", sizeof(S < float >::vector_type));
    12    S<float> x;
    13    x.pr_size();
    14    return 0;
    15  }
Comment 2 Andrew Pinski 2005-01-12 21:31:53 UTC
Another example (which is rejected):
#include <stdio.h>
template < typename Val > struct S {
typedef Val vector_type __attribute__((vector_size(16)));
void pr_size() { printf ("size = %d\n", sizeof(vector_type)); }
};
int main()
{
printf ("size = %d\n", sizeof(S < float >::vector_type));
S<float> x;
x.pr_size();
return 0;
}
Comment 3 Andrew Pinski 2005-05-01 02:53:01 UTC
Now we get an error:
t.cc:3: sorry, unimplemented: applying attributes to template parameters is not implemented

So this is definitely PR 17743
Comment 4 Andrew Pinski 2006-08-26 04:26:17 UTC
This is not target specific.
Comment 5 Jason Merrill 2007-09-23 02:36:46 UTC
Subject: Bug 19407

Author: jason
Date: Sun Sep 23 02:36:34 2007
New Revision: 128681

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=128681
Log:
        PR c++/19407
        * cp/cp-tree.h (ATTR_IS_DEPENDENT): New macro.
        (MAYBE_TAGGED_TYPE_P): Remove.
        * cp/pt.c (apply_late_template_attributes): Check ATTR_IS_DEPENDENT
        instead of calling is_late_template_attribute again.
        (tsubst_decl) [TYPE_DECL]: Just check if the name is the tag.
        (tsubst): A typedef is a TYPE_NAME != TYPE_MAIN_DECL.
        Don't crash on typedefs from non-template classes.
        * cp/decl2.c (grokfield): Don't sorry about attrs on template parms.
        (is_late_template_attribute): All attributes applied to template
        parms or typename types are dependent.  Static, take decl.
        (splice_template_attributes): Pass decl through.
        (save_template_attributes): Likewise.
        * attribs.c (lookup_attribute_spec): Split out...
        (decl_attributes): From here.
        * tree.h: Declare it.

Added:
    trunk/gcc/testsuite/g++.dg/ext/tmplattr5.C
    trunk/gcc/testsuite/g++.dg/template/typedef7.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/attribs.c
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/decl2.c
    trunk/gcc/cp/pt.c
    trunk/gcc/testsuite/g++.dg/ext/attrib20.C
    trunk/gcc/tree.h

Comment 6 Jason Merrill 2007-09-23 02:39:06 UTC
Fixed for 4.3.0.