8086027: Multiple STATIC_ASSERTs at class scope doesn't work
authorkbarrett
Tue, 09 Jun 2015 15:05:47 -0400
changeset 31340 2f9ff278bb13
parent 31334 d55c96b36b5f
child 31341 10fdb147cc97
8086027: Multiple STATIC_ASSERTs at class scope doesn't work Summary: Make supporting typedef name unique via __LINE__ concatenation Reviewed-by: dholmes, brutisso
hotspot/src/share/vm/utilities/debug.cpp
hotspot/src/share/vm/utilities/debug.hpp
hotspot/src/share/vm/utilities/macros.hpp
--- a/hotspot/src/share/vm/utilities/debug.cpp	Mon Jun 08 15:40:28 2015 +0200
+++ b/hotspot/src/share/vm/utilities/debug.cpp	Tue Jun 09 15:05:47 2015 -0400
@@ -770,3 +770,31 @@
 }
 
 #endif // !PRODUCT
+
+//////////////////////////////////////////////////////////////////////////////
+// Test multiple STATIC_ASSERT forms in various scopes.
+
+#ifndef PRODUCT
+
+// namespace scope
+STATIC_ASSERT(true);
+STATIC_ASSERT(true);
+STATIC_ASSERT(1 == 1);
+STATIC_ASSERT(0 == 0);
+
+void test_multiple_static_assert_forms_in_function_scope() {
+  STATIC_ASSERT(true);
+  STATIC_ASSERT(true);
+  STATIC_ASSERT(0 == 0);
+  STATIC_ASSERT(1 == 1);
+}
+
+// class scope
+struct TestMultipleStaticAssertFormsInClassScope {
+  STATIC_ASSERT(true);
+  STATIC_ASSERT(true);
+  STATIC_ASSERT(0 == 0);
+  STATIC_ASSERT(1 == 1);
+};
+
+#endif // !PRODUCT
--- a/hotspot/src/share/vm/utilities/debug.hpp	Mon Jun 08 15:40:28 2015 +0200
+++ b/hotspot/src/share/vm/utilities/debug.hpp	Tue Jun 09 15:05:47 2015 -0400
@@ -223,7 +223,8 @@
 template<> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
 
 #define STATIC_ASSERT(Cond) \
-  typedef char STATIC_ASSERT_DUMMY_TYPE[ STATIC_ASSERT_FAILURE< (Cond) >::value ]
+  typedef char PASTE_TOKENS(STATIC_ASSERT_DUMMY_TYPE_, __LINE__)[ \
+    STATIC_ASSERT_FAILURE< (Cond) >::value ]
 
 // out of shared space reporting
 enum SharedSpaceType {
--- a/hotspot/src/share/vm/utilities/macros.hpp	Mon Jun 08 15:40:28 2015 +0200
+++ b/hotspot/src/share/vm/utilities/macros.hpp	Tue Jun 09 15:05:47 2015 -0400
@@ -34,6 +34,15 @@
 // Makes a string of the macro expansion of a
 #define XSTR(a) STR(a)
 
+// Apply pre-processor token pasting to the expansions of x and y.
+// The token pasting operator (##) prevents its arguments from being
+// expanded.  This macro allows expansion of its arguments before the
+// concatenation is performed.  Note: One auxilliary level ought to be
+// sufficient, but two are used because of bugs in some preprocesors.
+#define PASTE_TOKENS(x, y) PASTE_TOKENS_AUX(x, y)
+#define PASTE_TOKENS_AUX(x, y) PASTE_TOKENS_AUX2(x, y)
+#define PASTE_TOKENS_AUX2(x, y) x ## y
+
 // -DINCLUDE_<something>=0 | 1 can be specified on the command line to include
 // or exclude functionality.