Boost logo

Boost :

Subject: Re: [boost] [typeof] GCC error: expression not defined in this scope
From: Vicente Botet (vicente.botet_at_[hidden])
Date: 2011-02-25 15:06:47


Lorenzo Caminiti wrote:
>
> On Mon, Feb 7, 2011 at 5:29 PM, Steven Watanabe <watanabesj_at_[hidden]>
> wrote:
>
>
> Hello all,
>
> Why the following TYPEOF code does not compile on GCC but it does on
> MSVC? Is this a GCC bug? If so, is there a workaround for it?
>
> #include <boost/typeof/typeof.hpp>
>
> int f() { return -1; }
>
> template<typename T>
> void g(T x) {
> int (deduce_func)();
> typedef BOOST_TYPEOF_TPL(deduce_func) func_type; // error also if
> TYPEOF is used instead of TYPEOF_TPL
>
> struct s {
> void call(func_type func) { func(); } // line 12
> } ss;
> ss.call(f); // line 14
> }
>
> int main() {
> g(1); // line 18
> return 0;
> }
>
> $ g++ -Wall -Werror -I../../.. r03.cpp
> r03.cpp: In member function ‘void g(T)::s::call(__typeof__
> (boost::type_of::ensure_obj(deduce_func))) [with T = int]’:
> r03.cpp:14: instantiated from ‘void g(T) [with T = int]’
> r03.cpp:18: instantiated from here
> r03.cpp:12: error: ‘deduce_func’ was not declared in this scope
>
> What is this error? I don't understand it because with the local
> struct at line 12 I am just accessing the type generated by the
> typedef and not the actual expression that was used to deduce such a
> type...
>
>

If I understand deduce_func should be a pointer to a function returning int.
The declaration
    int (deduce_func)();

seems suspect to me. Have you tried with
    int (*deduce_func)();

HTH,
Vicente

-- 
View this message in context: http://boost.2283326.n4.nabble.com/typeof-GCC-error-expression-not-defined-in-this-scope-tp3324797p3325104.html
Sent from the Boost - Dev mailing list archive at Nabble.com.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk