The following program correctly generates an error:
---
int& g_foo;
---
$ ~/gcc/bin/g++ -c -Wall test.cpp
test.cpp:1: error: 'g_foo' declared as reference but not initialized

The following program fails to generate an error (which seemingly is a
violation of the C++ standard) but also doesn't even generate a warning, even
with -Wall.
---
extern int& g_foo;
int& g_foo;
---
$ ~/gcc/bin/g++ -c -Wall test.cpp
$

At this point g_foo is a null reference, without having ever dereferenced a
null pointer, which also seemingly is a violation of the C++ standard.

This is the case with some older gcc versions I tried - seemingly not a
regression, at least not a recent one.


-- 
           Summary: extern declaration causes uninitialized reference to go
                    unnoticed
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: appfault at hotmail dot com


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

Reply via email to