public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19552] New: Compile error on template member function called from template function
@ 2005-01-20 23:29 andres_takach at mentor dot com
  2005-01-21  0:37 ` [Bug c++/19552] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andres_takach at mentor dot com @ 2005-01-20 23:29 UTC (permalink / raw)
  To: gcc-bugs

Test file is only 30 lines (t5.cxx, the t5.ii is indentical and is included at
the end. Comments explain the bug:


template<int W>
class mc_foo {
  int _d;
public:
  mc_foo() {}
  mc_foo(int x) { _d = x; }
  mc_foo(const mc_foo &x) { _d = x._d; }
                                                                               
                                                                                    
  template<int W2>
  void f(int i) {}
};
                                                                               
                                                                                    
template <int W3>
void g( mc_foo<W3> val) {
                                                                               
                                                                                    
  mc_foo<16> val2 = val;
  mc_foo<W3> val3 = val;    // W3 == 16 in this example
                                                                               
                                                                                    
  // the two following lines should be equivalent, but gcc3.4.3 is generating error
  // on val3.f<16>(0). It seems like val3 is not fully resolved and gcc then thinks
  // "<" is "less than" rather than the syntax for template
                                                                               
                                                                                    
  val2.f<16>(0);  // this works fine
  val3.f<16>(0);  // this produces error "invalid use of member (did you forget
the `&' ?)"
}
                                                                               
                                                                                    
int main() {
  mc_foo<16> y(1);
  g(y);
}




 ~/local/bin/c++ -v -save-temps t5.cxx
Reading specs from
/.automount/streak/root/scratch1/takach/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/specs
Configured with: ./configure
Thread model: posix
gcc version 3.4.3
 /.automount/streak/root/scratch1/takach/bin/../libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1plus
-E -quiet -v -iprefix
/.automount/streak/root/scratch1/takach/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/
-D_GNU_SOURCE t5.cxx -mtune=pentiumpro -o t5.ii
ignoring nonexistent directory
"/.automount/streak/root/scratch1/takach/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../i686-pc-linux-gnu/include"
ignoring duplicate directory
"/user/takach/local/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3"
ignoring duplicate directory
"/user/takach/local/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/i686-pc-linux-gnu"
ignoring duplicate directory
"/user/takach/local/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/backward"
ignoring nonexistent directory "NONE/include"
ignoring duplicate directory
"/user/takach/local/lib/gcc/i686-pc-linux-gnu/3.4.3/include"
ignoring nonexistent directory
"/user/takach/local/lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /.automount/streak/root/scratch1/takach/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3
 /.automount/streak/root/scratch1/takach/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/i686-pc-linux-gnu
 /.automount/streak/root/scratch1/takach/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/../../../../include/c++/3.4.3/backward
 /.automount/streak/root/scratch1/takach/bin/../lib/gcc/i686-pc-linux-gnu/3.4.3/include
 /usr/local/include
 /usr/include
End of search list.
 /.automount/streak/root/scratch1/takach/bin/../libexec/gcc/i686-pc-linux-gnu/3.4.3/cc1plus
-fpreprocessed t5.ii -quiet -dumpbase t5.cxx -mtune=pentiumpro -auxbase t5
-version -o t5.s
GNU C++ version 3.4.3 (i686-pc-linux-gnu)
        compiled by GNU C version 3.2.3 20030502 (Red Hat Linux 3.2.3-34).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
t5.cxx: In function `void g(mc_foo<W3>) [with int W3 = 16]':
t5.cxx:29:   instantiated from here
t5.cxx:24: error: invalid use of member (did you forget the `&' ?)


Contents of t5.ii
# 1 "t5.cxx"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "t5.cxx"
template<int W>
class mc_foo {
  int _d;
public:
  mc_foo() {}
  mc_foo(int x) { _d = x; }
  mc_foo(const mc_foo &x) { _d = x._d; }
                                                                               
                                                                                    
  template<int W2>
  void f(int i) {}
};
                                                                               
                                                                                    
template <int W3>
void g( mc_foo<W3> val) {
                                                                               
                                                                                    
  mc_foo<16> val2 = val;
  mc_foo<W3> val3 = val;
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                    
  val2.f<16>(0);
  val3.f<16>(0);
}
                                                                               
                                                                                    
int main() {
  mc_foo<16> y(1);
  g(y);
}

-- 
           Summary: Compile error on template member function called from
                    template function
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: critical
          Priority: P1
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: andres_takach at mentor dot com
                CC: gcc-bugs at gcc dot gnu dot org
  GCC host triplet: 2.4.21-15.ELsmp  #1 i686 i686 i386


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19552


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/19552] Compile error on template member function called from template function
  2005-01-20 23:29 [Bug c++/19552] New: Compile error on template member function called from template function andres_takach at mentor dot com
@ 2005-01-21  0:37 ` pinskia at gcc dot gnu dot org
  2005-01-21  2:34 ` pinskia at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-21  0:37 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-21 00:37 -------
The code is invalid (by the C++ standard)
  mc_foo<W3> val3 = val;    // W3 == 16 in this example
val3.f<16>(0);

Since val3 is dependent name, we don't know that val3.f is a template so we reject the code.

you need to use the template keyword like so:
val3.template f<16>(0);


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19552


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/19552] Compile error on template member function called from template function
  2005-01-20 23:29 [Bug c++/19552] New: Compile error on template member function called from template function andres_takach at mentor dot com
  2005-01-21  0:37 ` [Bug c++/19552] " pinskia at gcc dot gnu dot org
@ 2005-01-21  2:34 ` pinskia at gcc dot gnu dot org
  2005-01-21 18:58 ` andres_takach at mentorg dot com
  2005-01-21 20:45 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-21  2:34 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-21 02:34 -------
*** Bug 19559 has been marked as a duplicate of this bug. ***

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19552


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/19552] Compile error on template member function called from template function
  2005-01-20 23:29 [Bug c++/19552] New: Compile error on template member function called from template function andres_takach at mentor dot com
  2005-01-21  0:37 ` [Bug c++/19552] " pinskia at gcc dot gnu dot org
  2005-01-21  2:34 ` pinskia at gcc dot gnu dot org
@ 2005-01-21 18:58 ` andres_takach at mentorg dot com
  2005-01-21 20:45 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: andres_takach at mentorg dot com @ 2005-01-21 18:58 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From andres_takach at mentorg dot com  2005-01-21 18:58 -------
Subject: Re:  Compile error on template member function called
 from template function

Thanks for the workaround and for the fast response!

Looking at the standard this is what I see:

- mc_foo<W3> is a "dependent type" (14.6.2.1)
- val3.f<16> is a "type dependent expression" (14.6.2.2) since identifier val3 was defined with a "dependent type".
- Section 14.6.2 (last two sentences in paragraph 1) says:
    "If an operand of an operator is a type-depedent expression, the operator also denotes a dependent name. SUCH NAMES 
ARE UNBOUND AND ARE LOOKED UP AT THE POINT OF THE TEMPLATE INSTANTIATION (14.6.4.1) in both the context of the template 
definition and the context of the point of instantiation."

At the point of the template instantiation, the compiler does know that val3.f is a template. The code is therefore 
valid according to the C++ standard.

pinskia at gcc dot gnu dot org wrote:
> ------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-21 00:37 -------
> The code is invalid (by the C++ standard)
>   mc_foo<W3> val3 = val;    // W3 == 16 in this example
> val3.f<16>(0);
> 
> Since val3 is dependent name, we don't know that val3.f is a template so we reject the code.
> 
> you need to use the template keyword like so:
> val3.template f<16>(0);
> 
> 



-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19552


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/19552] Compile error on template member function called from template function
  2005-01-20 23:29 [Bug c++/19552] New: Compile error on template member function called from template function andres_takach at mentor dot com
                   ` (2 preceding siblings ...)
  2005-01-21 18:58 ` andres_takach at mentorg dot com
@ 2005-01-21 20:45 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-21 20:45 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-01-21 20:45 -------
(In reply to comment #3)
> Subject: Re:  Compile error on template member function called
>  from template function
> 

> - Section 14.6.2 (last two sentences in paragraph 1) says:
>     "If an operand of an operator is a type-depedent expression, the operator also denotes a 
dependent name. SUCH NAMES 
> ARE UNBOUND AND ARE LOOKED UP AT THE POINT OF THE TEMPLATE INSTANTIATION (14.6.4.1) in 
both the context of the template 
> definition and the context of the point of instantiation."
> 
> At the point of the template instantiation, the compiler does know that val3.f is a template. The code 
is therefore 
> valid according to the C++ standard.

No but this is about parse time and not instantiation time.  Let me find the reference this is 
documented in the release notes for 3.4 also.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19552


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-01-21 20:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-20 23:29 [Bug c++/19552] New: Compile error on template member function called from template function andres_takach at mentor dot com
2005-01-21  0:37 ` [Bug c++/19552] " pinskia at gcc dot gnu dot org
2005-01-21  2:34 ` pinskia at gcc dot gnu dot org
2005-01-21 18:58 ` andres_takach at mentorg dot com
2005-01-21 20:45 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).