This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15287] New: G++ fails when encountering the combined `[]' and `.*' operators in the context of templatized method/function


DESCRIPTION

G++ 3.4 wrongly recognizes some valid C++ syntax as an error:
This in particular happens when a class/structure is operated upon with
both `[]' and `.*' operators, like this:

(Class[C].*BoolMethod)();                                     //<1>

where Class is any C++ object; C is a size_t variable, and BoolMethod is a
pointer to method. An attachment is given as a concrete example of the
problem.

Some generic conditions are required to trigger the bug:

* This problem was originally discovered when `Class' is of the type
  `std::vector<something>'. But it turns out that any C++ object would
  trigger the error.

* The statement //<1> must be in a templatized function or class method.
  Look at the example: Uncomment line //[4] and comment //[5], then
  the error will not happen in `void Proc(_type2)'.


WORKAROUND

A temporary workaround is possible, by FIRST caching the `[]' operator
result, then applying the `.*' operator. But this may or may not work,
depending on what actually happens with the `[]' operator.

Consider my given example:
* If you compile with -DWORK_AROUND_BUG, the error messages disappear.
* If you compile with -DWORK_AROUND_BUG=-1 instead, the same error message
  would re-appear. The addition of parantheses does not help.


VERSION KNOWN TO BE AFFECTED: 3.4

My gcc gives the following version/compilation info:

[wirawan@snowflake tmp]$ /usr/local/gcc-3.4.0/bin/g++ -v
Reading specs from /usr/local/gcc-3.4.0/lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: ../gcc-3.4.0/configure --prefix=/usr/local/gcc-3.4.0
--disable-nls --enable-languages=c,c++,f77 --enable-shared --with-cpu=i686
--with-tune=i686 --with-arch=i686 --enable-threads=posix
--enable-__cxa_atexit
Thread model: posix
gcc version 3.4.0


OTHER VERSIONS

This error does NOT happen with GNU C++ version 3.3.x and earlier.

-- 
           Summary: G++ fails when encountering the combined `[]' and `.*'
                    operators in the context of templatized method/function
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wirawan0 at softhome dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]