public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/27347]  New: static array member specialization failure
@ 2006-04-28 10:15 maxim dot yegorushkin at gmail dot com
  2006-04-28 13:33 ` [Bug c++/27347] [4.0/4.1/4.2 Regression] " rguenth at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: maxim dot yegorushkin at gmail dot com @ 2006-04-28 10:15 UTC (permalink / raw)
  To: gcc-bugs

$ cat exp.cpp
template<class T> struct type_name { static char const name[]; };
template<class T> char const type_name<T>::name[] = "";
template<> char const type_name<int>::name[] = "int";

$ g++ -v exp.cpp
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-libgcj-multifile
--enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre
--host=x86_64-redhat-linux
Thread model: posix
gcc version 4.0.2 20051125 (Red Hat 4.0.2-8)
 /usr/libexec/gcc/x86_64-redhat-linux/4.0.2/cc1plus -quiet -v -D_GNU_SOURCE
exp.cpp -quiet -dumpbase exp.cpp -mtune=k8 -auxbase exp -version -o
/tmp/ccC0PGNG.s
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../include/c++/4.0.2

/usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../include/c++/4.0.2/x86_64-redhat-linux
 /usr/lib/gcc/x86_64-redhat-linux/4.0.2/../../../../include/c++/4.0.2/backward
 /usr/local/include
 /usr/lib/gcc/x86_64-redhat-linux/4.0.2/include
 /usr/include
End of search list.
GNU C++ version 4.0.2 20051125 (Red Hat 4.0.2-8) (x86_64-redhat-linux)
        compiled by GNU C version 4.0.2 20051125 (Red Hat 4.0.2-8).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
exp.cpp:3: error: initializer-string for array of chars is too long

Comeau online compiles the code just fine. If the sizeof of the initializer at
line 2 is at least as big as sizeof("int") then it compiles fine with g++.

The error is reproducible with g++ 4.0.2 and 4.1.0.


-- 
           Summary: static array member specialization failure
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: maxim dot yegorushkin at gmail dot com


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


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

* [Bug c++/27347] [4.0/4.1/4.2 Regression] static array member specialization failure
  2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
@ 2006-04-28 13:33 ` rguenth at gcc dot gnu dot org
  2006-04-29  3:35 ` pinskia at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-04-28 13:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2006-04-28 13:33 -------
Confirmed.  Regression with the new C++ parser.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |rejects-valid
      Known to fail|                            |3.4.6 4.0.3 4.1.0 4.2.0
      Known to work|                            |3.3.6
   Last reconfirmed|0000-00-00 00:00:00         |2006-04-28 13:33:30
               date|                            |
            Summary|static array member         |[4.0/4.1/4.2 Regression]
                   |specialization failure      |static array member
                   |                            |specialization failure
   Target Milestone|---                         |4.0.4


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


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

* [Bug c++/27347] [4.0/4.1/4.2 Regression] static array member specialization failure
  2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
  2006-04-28 13:33 ` [Bug c++/27347] [4.0/4.1/4.2 Regression] " rguenth at gcc dot gnu dot org
@ 2006-04-29  3:35 ` pinskia at gcc dot gnu dot org
  2006-06-04 18:39 ` mmitchel at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-29  3:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2006-04-29 03:35 -------
The problem I think is the non specialization is getting in the way in that:
template<class T> char const type_name<T>::name[] = "";
is recording the size as 1.

Another testcase with a slightly different error:
emplate<class T> struct type_name { static int const name[]; };
template<class T> int const type_name<T>::name[] = {0};
template<> int const type_name<int>::name[] = {0, 1, 2, 3};


int f(void)
{
  return type_name<int>::name[2];
}


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
      Known to fail|3.4.6 4.0.3 4.1.0 4.2.0     |3.4.6 4.0.3 4.1.0 4.2.0
                   |                            |3.4.0
   Last reconfirmed|2006-04-28 13:33:30         |2006-04-29 03:35:43
               date|                            |


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


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

* [Bug c++/27347] [4.0/4.1/4.2 Regression] static array member specialization failure
  2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
  2006-04-28 13:33 ` [Bug c++/27347] [4.0/4.1/4.2 Regression] " rguenth at gcc dot gnu dot org
  2006-04-29  3:35 ` pinskia at gcc dot gnu dot org
@ 2006-06-04 18:39 ` mmitchel at gcc dot gnu dot org
  2006-06-14 22:17 ` mmitchel at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-06-04 18:39 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P1


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


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

* [Bug c++/27347] [4.0/4.1/4.2 Regression] static array member specialization failure
  2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
                   ` (2 preceding siblings ...)
  2006-06-04 18:39 ` mmitchel at gcc dot gnu dot org
@ 2006-06-14 22:17 ` mmitchel at gcc dot gnu dot org
  2006-06-14 23:47 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-06-14 22:17 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |mark at codesourcery dot com
                   |dot org                     |
             Status|NEW                         |ASSIGNED


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


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

* [Bug c++/27347] [4.0/4.1/4.2 Regression] static array member specialization failure
  2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
                   ` (3 preceding siblings ...)
  2006-06-14 22:17 ` mmitchel at gcc dot gnu dot org
@ 2006-06-14 23:47 ` mmitchel at gcc dot gnu dot org
  2006-06-15  1:32 ` mmitchel at gcc dot gnu dot org
  2006-06-15  2:00 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-06-14 23:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from mmitchel at gcc dot gnu dot org  2006-06-14 22:17 -------
I'm not convinced this is a bug in G++.  

If the first line were:

  template<class T> struct type_name { static char const name[1]; };

then there would be no question that the specialization was invalid.  Since the
type of an array variable is indeed determined by its initializer, I don't see
any different between that case and the case in the test case.

I've sent mail to EDG to clarify.


-- 


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


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

* [Bug c++/27347] [4.0/4.1/4.2 Regression] static array member specialization failure
  2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
                   ` (4 preceding siblings ...)
  2006-06-14 23:47 ` mmitchel at gcc dot gnu dot org
@ 2006-06-15  1:32 ` mmitchel at gcc dot gnu dot org
  2006-06-15  2:00 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-06-15  1:32 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from mmitchel at gcc dot gnu dot org  2006-06-15 00:27 -------
John Spicer and I discussed this issue, but I don't think we've got a clear
resolution.  John believes the example is valid.

However, I asked:

=====
 template <int> void g();

 template <typename T>
 struct S {
   static int i[];
   void f();
 };

 template <typename T>
 int S<T>::i[] = { 1 };

 template <typename T>
 void S<T>::f() {
   g<sizeof (i) / sizeof (int)>();
 }

 template <typename T>
 int S<int>::i[] = { 1, 2 };

Which g is called from S<int>::f()?

If the program is valid, then surely one would expect g<2> to be called.

If the program is valid, does S<T>::i have a non-dependent type in
S<T>::f?  If so, is it incomplete, or is it int[1]?  (Here, int[1] would
be surprising, since S<int>::i actually has type int[2].)

If the program is invalid, why?
=====

John says that this is core issue #408.  I'm not sure that's really the same
issue, but it's related.

The problem I see is that if S<T>::i has a non-dependent type, it must be
either int[1] or int[].  In the former case, the specialization is invalid.  In
the latter case, S<T>::f is invalid since it applies sizeof to an incomplete
type.


-- 


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


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

* [Bug c++/27347] [4.0/4.1/4.2 Regression] static array member specialization failure
  2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
                   ` (5 preceding siblings ...)
  2006-06-15  1:32 ` mmitchel at gcc dot gnu dot org
@ 2006-06-15  2:00 ` mmitchel at gcc dot gnu dot org
  6 siblings, 0 replies; 8+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2006-06-15  2:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from mmitchel at gcc dot gnu dot org  2006-06-15 01:51 -------
John and I talked about this a bit more, and he's going to update the core
issue.

To me, there are only a few options here:

1. S<T>::i has non-dependent type "int[]".

In that case, the sizeof expression is an error.

2. S<T>::i has non-dependent type "int[1]".

In that case, the explicit specialization is an error.

3. S<T>::i has dependent type.

But, why should it?  It doesn't use any template parameters.

I like option #2 best.  If the in-class declaration for the code in the
original report were "static char const name[1]" then everyone would agree the
specialization is invalid.  Why should it make a difference whether the size of
the array is explicitly specified or implied by the initializer?  That
distinction doesn't matter anywhere else in the language.

My second choice is option #1.

I'm going to close this PR as invalid.  I don't think there's clear support for
this code in the standard.


-- 

mmitchel at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2006-06-15  1:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-04-28 10:15 [Bug c++/27347] New: static array member specialization failure maxim dot yegorushkin at gmail dot com
2006-04-28 13:33 ` [Bug c++/27347] [4.0/4.1/4.2 Regression] " rguenth at gcc dot gnu dot org
2006-04-29  3:35 ` pinskia at gcc dot gnu dot org
2006-06-04 18:39 ` mmitchel at gcc dot gnu dot org
2006-06-14 22:17 ` mmitchel at gcc dot gnu dot org
2006-06-14 23:47 ` mmitchel at gcc dot gnu dot org
2006-06-15  1:32 ` mmitchel at gcc dot gnu dot org
2006-06-15  2:00 ` mmitchel 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).