[Bug c++/20140] New: template function complains about "char-array initialized from wide string"

rwxr-xr-x at gmx dot de gcc-bugzilla@gcc.gnu.org
Tue Feb 22 17:06:00 GMT 2005


Hello,

this is my code:

template<typename T> void foo() {
    unsigned char s[] = "";
    (void)s;
}

int main() {
    /* removing either of the calls below makes the error disappear */
    foo<int>();
    foo<char>();
}

Compiling this program with g++[0] results in
try.cc: In function `void foo() [with T = char]':
try.cc:9:   instantiated from here
try.cc:2: error: char-array initialized from wide string

I think this is wrong because "" isn't a wide string. The error disappears
when I remove "unsigned" from the declaration of s, or when only a single
foo<T> is instantiated. The actual types don't matter; my original code
used function pointers.

HTH, Lukas
[0] g++ versions:
Reading specs from /usr/local/lib/gcc/i686-pc-linux-gnu/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --with-cpu=i686 --with-arch=i686 --with-tune=i686 --enable-__cxa_atexit
Thread model: posix
gcc version 3.4.3

Reading specs from /usr/local/dist/bin/../lib/gcc-lib/sparc-sun-solaris2.8/3.2.2/specs
Configured with: /compilefs/usr.local.compile/dist/fenk/gcc-3.2.2/configure --prefix=/usr/local/dist/DIR/GNU/gcc-3.2.2 --with-gnu-as --with-as=/usr/local/dist/DIR/GNU/binutils/bin/as --with-gnu-ld --with-ld=/usr/local/dist/DIR/GNU/binutils/bin/ld --with-dwarf2 --disable-multilib --with-local-prefix=/usr/local/dist
Thread model: posix
gcc version 3.2.2

-- 
           Summary: template function complains about "char-array
                    initialized from wide string"
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rwxr-xr-x at gmx dot de
                CC: gcc-bugs at gcc dot gnu dot org


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



More information about the Gcc-bugs mailing list