Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2003-12-27 07:51:36


Jim Apple <japple_at_[hidden]> writes:

>> and
>> it interacts with *any* code which does function pointer/reference
>> assignment.
>
> I'm not sure I understand this statement. If you mean it this file
> would compile (and cause the test to fail) for function
> pointer/reference, then I disagree. The compilers I tested emmitted
> the proper errors for non boost::function use.

I mean that I can reproduce the same kind of problem in a few lines
without any library, as you've shown below. I'm fairly certain that
no casts are needed; I've seen this problem in some experiments I did
once upon a time without any casts. So my point is, this isn't a
Boost.Function-specific issue.

=====

Example:
--------------------------------------------------------
void f(int = 0) {}
 

void (*g)(int) = f;
 

struct indirect {
   void (*call)();
   template<typename FType>
   void attempt(FType * p) {
     reinterpret_cast<FType *>(call)();
   }
   /*
   void attempt_fail() {
     reinterpret_cast<void (*)(int)>(call)();
   }
   */
   indirect(void (*p)(int)) : call(reinterpret_cast<void (*)()>(p)) {}
};
 

int main() {
   indirect x(f);
   x.attempt(f);
   //g();
}
--------------------------------------------------------

Uncommenting indirect::attempt_fail causes a "too few arguments"
compile error, as does uncommenting g(). However, g++ 3.3.1 and icc 8
both pass this with no errors, with -strict_ansi and -pedantic,
respectively.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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