Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2006-01-06 08:42:43


The following code doesn't compile on gcc 3.3.5

typedef int (fun)(bool);
fun& foo();

BOOST_STATIC_ASSERT((boost::is_same<BOOST_TYPEOF(foo()), fun>::value));

The error is

error: no matching function for call to `ensure_obj(int(&)(bool))'

This can be fixed by introducing more specialized ensure_obj:

template<class T> T& ensure_obj(const T&, int);
template<class R, class T0> R(& ensure_obj(R (&)(T0), ...) )(T0);
template<class R, class T0, class T1> R(& ensure_obj(R (&)(T0,T1), ...)
)(T0,T1);
// ...

( second argument is not required for gcc 3.3.5, it's there to resolve
ambuiguity on other compilers )

This fix has been tested on three different compilers:

> ~/pkgsrc-root/gcc3/bin/g++ -v
Reading specs from
/home/alnsn/pkgsrc-root/gcc3/lib/gcc-lib/i386-pc-freebsd6/3.3.5/specs
Configured with: ./configure --prefix=/home/alnsn/pkgsrc-root/gcc3
--host=i386-pc-freebsd6 --enable-shared --enable-languages=c++
Thread model: posix
gcc version 3.3.5

> g++ -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.4.4 [FreeBSD] 20050518

> /usr/local/intel_cc_80/bin/icpc -v -V
Intel(R) C++ Compiler for 32-bit applications, Version 8.1 Build
20050207Z Package ID: l_cc_pc_8.1.028
Copyright (C) 1985-2005 Intel Corporation. All rights reserved.
FOR NON-COMMERCIAL USE ONLY

Version 8.1

Also, other contexts mentioned by Arkadiy in other thread should be
modified.

BTW, why test/function_ref.cpp checks only test_wrapper type, not a
function reference?

-- 
Alexander Nasonov

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