Boost logo

Boost Users :

From: Richard (legalize+jeeves_at_[hidden])
Date: 2013-12-29 02:45:26

[Please do not mail me a copy of your followup]

boost-users_at_[hidden] spake the secret code
<518813FAAE539546847B8F61C0C9B2FA9B7B2388_at_[hidden]> thusly:

>Why is the behaviour different in these 2 scenarios? How is Boost able
>to differenciate between the 2 test cases in Scenario1?

The difference is that non-template test cases are generated
statically with unique names that cannot violate the one-definition

When you use BOOST_AUTO_TEST_CASE in multiple translation units inside
the same test suite (which is really just a glorified namespace),
the test cases must have unique names in order to not violate the one
definition rule.

When you use BOOST_AUTO_TEST_CASE_TEMPLATE, you get a uniquely named
static instance of a class whose constructor registers the dynamically
generated test cases for each of the template arguments.

The same templatized code appears in each translation unit, but C++
allows the linker to discard all but one of the multiple instantiations
of the same template.

In order to provide this explanation, what I did was to take your
template example code and expand the BOOST_AUTO_TEST_CASE_TEMPLATE
macro until it was resolved down into actual code.

"The Direct3D Graphics Pipeline" free book <>
     The Computer Graphics Museum <>
         The Terminals Wiki <>
  Legalize Adulthood! (my blog) <>

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at