Boost logo

Boost :

Subject: [boost] [Boost.Test] g++ compilation error due to ambiguity between template<class Cond, class T> struct boost::enable_if and class boost::unit_test::decorator::enable_if as well as the disable_if counterparts introduced after Boost 1.48.0 (up to at least svn rev. 76217)
From: Torsten Maehne (Torsten.Maehne_at_[hidden])
Date: 2012-01-10 12:59:33


Hello,

I would like to draw your attention to an issue in Boost.Test that I'm
experiencing with Boost trunk after the 1.48.0 release up until at least
SVN rev. 76398. Just including directly or indirectly boost/typeof/
native.hpp into a unit test module (which includes boost/test/included/
unit_test.hpp) will cause compiler errors with g++:

==== begin: test_boost_test_decorator_enable_if.cpp ====
#define BOOST_TEST_MODULE test_boost_test_decorator_enable_if
#include <boost/test/included/unit_test.hpp>
#include <boost/typeof/native.hpp>

//! \test Dummy test.
BOOST_AUTO_TEST_CASE(test_dummy)
{
  // do nothing
}
==== end: test_boost_test_decorator_enable_if.cpp ====

g++ reports:

In file included from test_boost_test_decorator_enable_if.cpp:62:
boost/typeof/native.hpp:30: error: expected nested-name-specifier before
‘enable_if’
boost/typeof/native.hpp:30: error: expected initializer before ‘<’ token
boost/typeof/native.hpp:34: error: expected nested-name-specifier before
‘disable_if’
boost/typeof/native.hpp:34: error: expected initializer before ‘<’ token

The reason is an ambiguity between template<class Cond, class T> struct
boost::enable_if and class boost::unit_test::decorator::enable_if in
boost/typeof/native.hpp, as well as the disable_if counterparts. The test
case compiles correctly against Boost 1.48.0 using Apple g++ 4.2.1,
MacPorts? g++ 4.5.3 and 4.6.2 as well as Apple clang++ 3.0 on Mac OS X
Lion 10.7.2 and Xcode 4.2.1. It fails to compile against Boost trunk
until at least svn rev. 76217 using any of the mentioned g++ versions.
Surprisingly, clang++ 3.0 is still able to correctly compile the test
case.

The test case is derived from test_signed_integer_output_with_karma.cpp
in Trac ticket #6126. During the discussion of ticket #6126 on the Boost-
Spirit-general mailing list, Jeroen Habraken identified the header boost/
test/tree/decorator.hpp as the origin for the compilation failure of the
test case against Boost trunk. He found the cause to be an ambiguity:

$ g++-mp-4.6 -o test_boost_test_decorator_enable_if
test_boost_test_decorator_enable_if.cpp -I.../boost-trunk
In file included from test_boost_test_decorator_enable_if.cpp:58:0:
boost/typeof/native.hpp:30:18: error: expected nested-name-specifier
before 'enable_if'
boost/typeof/native.hpp:30:27: error: expected initializer before '<'
token
boost/typeof/native.hpp:34:18: error: expected nested-name-specifier
before 'disable_if'
boost/typeof/native.hpp:34:28: error: expected initializer before '<'
token
These occur because the code states "typename enable_if<Cond, T>::type"
and the type name doesn't make sense in combination with
boost::unit_test::decorator::enable_if. When removing the typename, on
gets the following ambiguity error:

boost/typeof/native.hpp:30:9: error: reference to 'enable_if' is ambiguous
boost/utility/enable_if.hpp:36:10: error: candidates are: template<class
Cond, class T> struct boost::enable_if
boost/test/tree/decorator.hpp:184:23: error: class
boost::unit_test::decorator::enable_if
showing the conflict between template<class Cond, class T> struct
boost::enable_if and class boost::unit_test::decorator::enable_if.

As enable_if is often used without being fully qualified this breaks in a
major fashion. Since boost/test/tree/decorator.hpp seems to be quite new
(added 2011-10-02 11:00:16 +0200) it might be best fixed there.

My search on trac for boost::unit_test::decorator_enable_if turned up
changeset 74663 by rogeeff, who I therefore put in CC of the ticket 6331,
which describes the findings of Jeroen and me. However, there hasn't been
any feedback over the past 12 days. Therefore, I'm posting it now to the
Boost.Devel mailing list hoping that the issue can be resolved before
Boost 1.49 is released.

Regards,

Torsten Maehne


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