🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #1013

g++ 2.2.2 template bug?

#1013
From: Philippe F. Bertrand
Date: Thu, 01 Oct 1992 18:36
89 lines
2935 bytes
Please reply directly as I normally do not read this group.  Thanks.

g++ junk.c -c junk.b
version 2.2.2

PROBLEM 1
=========

template < char * b >
class C {
     char * B;
   public:
   C( );
};

template < char * b > C<b>::C( ) {
  B = b;
  printf( "%s\n", b );
}

void test( ) {

  C<"wewe"> bar;

}

----------
junk.c: In function `void  test ()':
junk.c:16: invalid pointer constant for template parameter
 <pointer_type 1005eeb0
    type <integer_type 1005ae68 char permanent QI
        size <integer_cst 1005aee8 constant permanent 8
        align 8 symtab 0 precision 8
        min <integer_cst 1005aeb8 constant permanent -128
        max <integer_cst 1005aed0 constant permanent 127
        pointer_to_this <pointer_type 1005eeb0>
    unsigned permanent SI
    size <integer_cst 1005ae00 type <integer_type 1005ad80 int> constant permanent 32
    align 16 symtab 0
 <addr_expr 10073c48
    type <pointer_type 1004e3b8
        type <array_type 1004e338 type <integer_type 1005ae68 char>
            BLK
            size <integer_cst 1004e3a0 constant 40
            align 8 symtab 0 domain <integer_type 1004e2e8>
            pointer_to_this <pointer_type 1004e3b8>
        unsigned SI
        size <integer_cst 1005ae00 constant permanent 32
        align 16 symtab 0
    constant permanent
    arg 0 <string_cst 10073c60 type <array_type 1004e338>
        constant permanent static "wewe"
junk.c: At top level:
junk.c:6: please fix above error, and try recompiling.


PROBLEM 2 - attempt to bipass/correct passing of ptr to string
=========

template < char * b >
class C {
     char * B;
   public:
   C( );
};

template < char * b > C<b>::C( ) {
  B = b;
  printf( "%s\n", b );
}

void test( ) {

  const char *foobar = "FooBar";
  C<foobar> bar;

}

---------------------------
junk.c: In function `void  test ()':
junk.c:17: warning: initialization of non-`const *' pointer from `const *'
junk.c:17: invalid pointer constant for template parameter
junk.c:17: please fix above error, and try recompiling.

removing the 'const' still results with the 'invalid pointer' error

- Philippe F. Bertrand                          pfbertrand@watcgl.uwaterloo.ca 
Computer Graphics Lab, Department of Computer Science,
University of Waterloo, Waterloo, Canada  N2L 3G1
Technical Details
Message-ID: <BvGH0u.476@watcgl.uwaterloo.ca>
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!constellation!convex!convex!cs.utexas.edu!sun-barr!ames!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!watcgl.uwaterloo.ca!pfbertra

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!constellation!convex!convex!cs.utexas.edu!sun-barr!ames!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!watcgl.uwaterloo.ca!pfbertra
From: pfbertra@watcgl.uwaterloo.ca (Philippe F. Bertrand)
Subject: g++ 2.2.2 template bug?
Message-ID: <BvGH0u.476@watcgl.uwaterloo.ca>
Sender: gnulists@ai.mit.edu
Organization: Computer Graphics Lab [CGL], University of Waterloo
Distribution: gnu
Date: Thu, 1 Oct 1992 18:36:18 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 90