psmason / googletest

Automatically exported from code.google.com/p/googletest
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

ASSERT_THROW, ASSERT_NO_THROW macros are sensitive to unprotected commas #219

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
ASSERT_THROW( p->foo<short,8>(), std::out_of_range);

when compiled with gcc 4.4.1 on Ubuntu,  I get an error message similar to 
this:
error: macro "ASSERT_THROW" passed 3 arguments, but takes just 2.

This happens because of unprotected comma between "short" and "8".
There is a simple workaround:
ASSERT_THROW( (p->foo<short,8>()), std::out_of_range);
which compiles fine, but it would be nice if I didn't have to remember to 
use parenthesis in some cases.

What version of the product are you using? On what operating system?
I use gtese 1.4.0 on ubuntu karmic koala

Original issue reported on code.google.com by khr...@gmail.com on 9 Nov 2009 at 1:26

GoogleCodeExporter commented 9 years ago
Thanks for your report. Commas in macro parameters are general problem in 
C/C++. 
The suggested solutions are to either take the parameter inside the parentheses 
or to 
alias the parameter somehow to remove the comma from the call site. See 
http://www.google.com/search?sourceid=chrome&ie=UTF-
8&q=c%2B%2B+commas+in+macro+parameters for examples.

Inside Google Test, there is little we can do to fix this. :-(

Original comment by vladlosev on 12 Nov 2009 at 6:47