g++ rejects the following operator() declaration: $cat bug.cpp struct s { typedef void f(void); f operator(); }; $g++ -c bug.cpp + exec /usr/bin/g++ -c bug.cpp bug.cpp:4: error: declaration of 'operator()' as non-function $g++ -v Using built-in specs. Target: i486-linux-gnu Configured with: ../src/configure -v --enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2 --enable-clocale=gnu --enable-libstdcxx-debug --enable-mpfr --enable-targets=all --enable-checking=release --build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu Thread model: posix gcc version 4.2.3 20071014 (prerelease) (Debian 4.2.2-3) $
According to my reading of the c++ standard (second edition, 2003-10-15), this is valid c++. First of all how the operator function is declared: 13.5 Overloaded operators [over.oper] 1 A function declaration having one of the following /operator-function-id/s as its name declares an /operator function/. An operator function is said to /implement/ the operator named in its /operator-function-id/. [... lists operator()] The construction above declares operator(), but is it a function declaration? Since function declaration is not italicized, I take it to mean any form of declaration that declares a function, not just the syntactic form that uses the explicit argument list. The standard allows such a member declaration: 9.3 Member functions [class.mfct] 9 [/Note:/ a member function can be declared (but not defined) using a typedef for a function type. The resulting member function has exactly the same type as it would have if the function declarator were provided explicitly, see 8.3.5. [...] I'm taking member functions to subsume member operators... A note about class template member functions supports my view, as it explicitly forbids the declaration when f is a template argument, but not otherwise: 14.3.1 Template type arguments [temp.arg.type] 3 If a declaration acquires a function type through a type dependent on a /template-parameter/ and this causes a declaration that does not use the syntactic form of a function declarator to have function type, the program is ill-formed. [...] Note also that this paragraph talks about "the syntactic form of a function declarator", suggesting that there might be other forms of declaring a function. Thanks. -- Summary: Cannot declare operator() using function typedef Product: gcc Version: 4.2.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: zweije at xs4all dot nl GCC build triplet: i486-linux-gnu GCC host triplet: i486-linux-gnu GCC target triplet: i486-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33972