[EMAIL PROTECTED]:/tmp$ cat > non-lvalue-pmf.cpp
struct Receive {
};

struct TcpStats {
    Receive rx;
};

typedef void (Receive::*StatsGatherer)(void);

template <StatsGatherer gatherStats>
void test(TcpStats* tcpStats) {
    (tcpStats->rx.*gatherStats)();
}
[EMAIL PROTECTED]:/tmp$ g++ -W -Wall -pedantic -g   -c -o non-lvalue-pmf.o 
non-lv
alue-pmf.cpp
non-lvalue-pmf.cpp: In function ?void test(TcpStats*)?:
non-lvalue-pmf.cpp:12: error: lvalue required as unary '&' operand
[EMAIL PROTECTED]:/tmp$

If this is indeed a bug then it's a regression between 3.3.6 (Debian
1:3.3.6-15) and Debian 4.2.1-5:

[EMAIL PROTECTED]:/tmp$ g++-3.3 -W -Wall -pedantic -g   -c -o non-lvalue-pmf.o
non-lvalue-pmf.cpp 
[EMAIL PROTECTED]:/tmp$ 

The regression, if that's what it is, was before 4.1.3 20070831 (prerelease)
(Debian 4.1.2-16).  The error message was improved between 4.1 and 4.2 but the
same underlying problem is in 4.1.

Various easy and harmless work-arounds are possible, for example, changing the
body of the function to read:

    Receive& rx = tcpStats->rx;
    (rx.*gatherStats)();

I tried to simplify the example further but I've been unable to.  One of the
changes that makes the problem go away is to replace the line:

template <StatsGatherer gatherStats>

With:

StatsGatherer gatherStats;

I don't see why that should affect the "lvalue-ness" of tcpStats->rx but I've
been wrong about such things many times before and I look forward to being
amazed.

Extra parentheses around (tcpStats->rx) don't help, just to save anyone from
looking up the operator precedence tables (which was the first thing I did).


-- 
           Summary: "lvalue required as unary '&' operand" with template pmf
           Product: gcc
           Version: 4.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mdorey at bluearc dot com
 GCC build triplet: x86_64-linux-gnu
  GCC host triplet: x86_64-linux-gnu
GCC target triplet: x86_64-linux-gnu


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

Reply via email to