Re: [Boost-bugs] [Boost C++ Libraries] #12712: BOOST_AUTO_TEST_SUITE: Generate unique names by using __COUNTER__

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #12712: BOOST_AUTO_TEST_SUITE: Generate unique names by using __COUNTER__
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-01-31 07:54:11


#12712: BOOST_AUTO_TEST_SUITE: Generate unique names by using __COUNTER__
--------------------------------------+------------------------
  Reporter: ki.stfu@… | Owner: renficiaud
      Type: Patches | Status: new
 Milestone: To Be Determined | Component: test
   Version: Boost Development Trunk | Severity: Problem
Resolution: | Keywords:
--------------------------------------+------------------------
Changes (by ki.stfu@…):

 * cc: ki.stfu@… (added)

Comment:

 `stdafx.h` doesn't play any special role in this case because I tested it
 on Linux with clang. So it can be renamed or even removed, it doesn't
 matter.

 The fact is that `__LINE__` is expanded to the current line number and if
 you have multiple files which define variables on the same line using this
 naming style then you will get an error.

 You can reproduce it by following:
 {{{
 user_at_u14:~$ ls
 _all.cpp bar.cpp foo.cpp
 user_at_u14:~$ cat foo.cpp
 #include <boost/test/unit_test.hpp>

 BOOST_AUTO_TEST_SUITE(data)
 BOOST_AUTO_TEST_SUITE(foo)

 BOOST_AUTO_TEST_SUITE_END()
 BOOST_AUTO_TEST_SUITE_END()
 user_at_u14:~$ cat bar.cpp
 #include <boost/test/unit_test.hpp>

 BOOST_AUTO_TEST_SUITE(data)
 BOOST_AUTO_TEST_SUITE(bar)

 BOOST_AUTO_TEST_SUITE_END()
 BOOST_AUTO_TEST_SUITE_END()
 user_at_u14:~$ cat _all.cpp
 #define BOOST_TEST_MAIN
 #include <boost/test/unit_test.hpp>

 #include "foo.cpp"
 #include "bar.cpp"
 user_at_u14:~$ clang++ _all.cpp
 In file included from _all.cpp:5:
 ./bar.cpp:3:1: error: redefinition of 'data_registrar3'
 BOOST_AUTO_TEST_SUITE(data)
 ^
 /usr/include/boost/test/unit_test_suite.hpp:45:73: note: expanded from
 macro 'BOOST_AUTO_TEST_SUITE'
 namespace suite_name { \
                                                                         ^
 /usr/include/boost/test/unit_test_suite.hpp:209:62: note: expanded from
 macro '\
 BOOST_AUTO_TU_REGISTRAR'
 static boost::unit_test::ut_detail::auto_test_unit_registrar BOOST_JOIN(
 BOOST_JOIN( test_name, _registrar ), __LINE__ )
                                                              ^
 /usr/include/boost/config/suffix.hpp:608:28: note: expanded from macro
 'BOOST_JOIN'
 #define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
                            ^
 /usr/include/boost/config/suffix.hpp:609:31: note: expanded from macro
 'BOOST_DO_JOIN'
 #define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
                               ^
 /usr/include/boost/config/suffix.hpp:610:32: note: expanded from macro
 'BOOST_DO_JOIN2'
 #define BOOST_DO_JOIN2( X, Y ) X##Y
                                ^
 <scratch space>:114:1: note: expanded from here
 data_registrar3
 ^
 ./foo.cpp:3:1: note: previous definition is here
 BOOST_AUTO_TEST_SUITE(data)
 ^
 /usr/include/boost/test/unit_test_suite.hpp:45:73: note: expanded from
 macro 'BOOST_AUTO_TEST_SUITE'
 namespace suite_name { \
                                                                         ^
 /usr/include/boost/test/unit_test_suite.hpp:209:62: note: expanded from
 macro '\
 BOOST_AUTO_TU_REGISTRAR'
 static boost::unit_test::ut_detail::auto_test_unit_registrar BOOST_JOIN(
 BOOST_JOIN( test_name, _registrar ), __LINE__ )
                                                              ^
 /usr/include/boost/config/suffix.hpp:608:28: note: expanded from macro
 'BOOST_JOIN'
 #define BOOST_JOIN( X, Y ) BOOST_DO_JOIN( X, Y )
                            ^
 /usr/include/boost/config/suffix.hpp:609:31: note: expanded from macro
 'BOOST_DO_JOIN'
 #define BOOST_DO_JOIN( X, Y ) BOOST_DO_JOIN2(X,Y)
                               ^
 /usr/include/boost/config/suffix.hpp:610:32: note: expanded from macro
 'BOOST_DO_JOIN2'
 #define BOOST_DO_JOIN2( X, Y ) X##Y
                                ^
 <scratch space>:96:1: note: expanded from here
 data_registrar3
 ^
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/12712#comment:7>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:21 UTC