[Bug c++/10941] New: g++ rejects valid use of own declaration in initializer

sbeasley@cs.uic.edu gcc-bugzilla@gcc.gnu.org
Thu May 22 17:14:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

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

           Summary: g++ rejects valid use of own declaration in initializer
           Product: gcc
           Version: 3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: sbeasley@cs.uic.edu
                CC: gcc-bugs@gcc.gnu.org
 GCC build triplet: i686-pc-linux
  GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin

3.3.1/1 of the C++ Standard says that an identifier is available immediately 
after its complete declarator and before its initializer. 8.5/1 
includes "direct initialization" syntax (the "(0)" in "int i(0);") as an 
initializer. Taken together, that means that the following code is well-formed:

  class A {
  public:
    explicit A (A &);

  private:
    explicit A (const A &);
    A &operator= (const A &);
  };

  A a(a);

However, g++ version 3.2 20020927 (prerelease) disagrees:
  
  <stdin>:10: `a' was not declared in this scope

NB: This code is a simplification of a comp.lang.c++ post as a possible way to 
making sure that an object is only used as a named automatic-duration variable 
(specifically, it represents a mutex that is supposed to protect the rest of 
the operations in its scope from concurrent access). In the proposed solution, 
the only accessible constructor requires a non-const reference which will only 
accept a non-const lvalue, the most obvious candidate (or the one mentioned in 
the documentation, should the user not recognize an obvious candidate) being 
the object itself. The only way to pass an object to its own constructor is if 
the object has a name. It's somewhat of a hack, but it's valid C++, it solves a 
real problem, and it's not accepted by GCC.



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the Gcc-bugs mailing list