Boost logo

Boost :

From: Jim Apple (japple_at_[hidden])
Date: 2003-12-25 12:42:20


Douglas Paul Gregor wrote:

> This should not compile.

Compiled for me with g++ 3.3.1, Intel 8 on linux. Here are some diffs
to note this compiler error:

--- Jamfile 2003-12-10 18:07:27.000000000 -0500
+++ Jamfile.new 2003-12-25 12:05:01.000000000 -0500
@@ -39,6 +39,8 @@

    [ compile-fail libs/function/test/function_test_fail2.cpp : : : : ]

+ [ compile-fail libs/function/test/function_test_fail3.cpp : : : : ]
+
    [ compile libs/function/test/function_30.cpp : : : : ]

    [ run libs/function/test/function_arith_cxx98.cpp : : : : ]

--- regression.cfg 2002-01-29 22:17:40.000000000 -0500
+++ regression.cfg.new 2003-12-25 12:33:13.000000000 -0500
@@ -9,6 +9,7 @@
  run libs/function/test/function_test.cpp
  compile-fail libs/function/test/function_test_fail1.cpp
  compile-fail libs/function/test/function_test_fail2.cpp
+compile-fail libs/function/test/function_test_fail3.cpp
  run libs/function/test/mixin_test.cpp
  run libs/function/test/policy_test.cpp
  run libs/function/test/stateless_test.cpp

---------------------------function_test_fail3.cpp----------------------------
// Boost.Function library

// This file copyright Jim Apple 2003-2004. Use, modification and
// distribution is subject to the Boost Software License, Version
// 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// For more information, see http://www.boost.org

#include <boost/test/minimal.hpp>
#include <boost/function.hpp>

using namespace std;
using namespace boost;

void f(int = 0) {}

int
test_main(int, char*[])
{
   function<void ()> g = f;
   g();

   BOOST_CRITICAL_ERROR("This should not have compiled.");

   return 0;
}

> int f(int x = 0) { return x; }
> int g(int x = 2) { return x; }
>
> int main()
> {
> boost::function<int()> fun;
> fun = f;
> cout << fun() << ' ';
> fun = g;
> cout << fun() << endl;
> }

gives 0 twice.

Jim


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