Author: sebor
Date: Tue Nov  8 11:10:34 2005
New Revision: 331866

URL: http://svn.apache.org/viewcvs?rev=331866&view=rev
Log:
2005-11-08  Martin Sebor  <[EMAIL PROTECTED]>

        STDCXX-57
        * instantiation_before_definition.h: Added a declaration of an
        unreferenced member function to prevent the instantiation of the
        (former) refererrent from implicitly instantiating it and causing
        a false positive.
        * instantiation_before_definition.cc: Added a definition of the member.
        * EXTERN_TEMPLATE_BEFORE_DEFINITION.cpp: New test to detect whether
        an extern template declaration corresponding to the explicit
        instantiation directive for the same template can appear lexically
        before the definition of the template (or members of class template).

Added:
    incubator/stdcxx/trunk/etc/config/src/EXTERN_TEMPLATE_BEFORE_DEFINITION.cpp 
  (with props)
Modified:
    incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.cc
    incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.h

Added: 
incubator/stdcxx/trunk/etc/config/src/EXTERN_TEMPLATE_BEFORE_DEFINITION.cpp
URL: 
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/EXTERN_TEMPLATE_BEFORE_DEFINITION.cpp?rev=331866&view=auto
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/EXTERN_TEMPLATE_BEFORE_DEFINITION.cpp 
(added)
+++ incubator/stdcxx/trunk/etc/config/src/EXTERN_TEMPLATE_BEFORE_DEFINITION.cpp 
Tue Nov  8 11:10:34 2005
@@ -0,0 +1,35 @@
+// checking for extern template before definition
+
+#if defined (_RWSTD_USE_CONFIG)
+#  include "config.h"
+#endif   // _RWSTD_USE_CONFIG
+
+#ifndef _RWSTD_NO_extern_template_before_definition_imp
+  // establish a dependency on the source file to get it
+  // compiled first and  link with the object file
+  // LDOPTS = ./extern_template_before_definition_imp.o
+#endif
+
+#ifdef _RWSTD_NO_IMPLICIT_INCLUSION
+   // tell "instantiation_before_definition.h" to #include its
+   // implementation file, instantiation_before_definition.cc
+#  define INCLUDE_CC_FILE
+#endif   // _RWSTD_NO_IMPLICIT_INCLUSION
+
+#define EXTERN_TEMPLATE
+#include "instantiation_before_definition.h"
+
+// test exercises the ability to declare an explicit instantiation
+// of a template using the "extern template" syntax and lexically
+// before the definition of the template (exercises, for example,
+// gcc 4.0.2 bug #24511:
+// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24511)
+
+int main ()
+{
+    InstantiatedBeforeDefined<int> ibd;
+
+    return   ibd.defined_first (0)
+           + ibd.instantiated_first (0)
+           + instantiated_before_defined (0);
+}

Propchange: 
incubator/stdcxx/trunk/etc/config/src/EXTERN_TEMPLATE_BEFORE_DEFINITION.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.cc
URL: 
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.cc?rev=331866&r1=331865&r2=331866&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.cc 
(original)
+++ incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.cc 
Tue Nov  8 11:10:34 2005
@@ -7,7 +7,17 @@
 }
 
 template <class T>
-T InstantiatedBeforeDefined<T>::instantiated_first (T t)
+T
+InstantiatedBeforeDefined<T>::
+instantiated_first (T t)
+{
+    return instantiated_before_defined (t);
+}
+
+template <class T>
+T
+InstantiatedBeforeDefined<T>::
+instantiated_first_and_referenced (T t) const
 {
     return instantiated_before_defined (t);
 }

Modified: 
incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.h
URL: 
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.h?rev=331866&r1=331865&r2=331866&view=diff
==============================================================================
--- incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.h 
(original)
+++ incubator/stdcxx/trunk/etc/config/src/instantiation_before_definition.h Tue 
Nov  8 11:10:34 2005
@@ -8,19 +8,35 @@
 struct InstantiatedBeforeDefined
 {
     T defined_first (T t) {
-        return instantiated_first (t);
+        return instantiated_first_and_referenced (t);
     }
 
-    // defined later, lexically after the explicit
-    // instantiation directives below, to exercise
+    // defined later, lexically after the explicit instantiation directives
+    // below, but not referenced by another member of this class to exercise
     // (for example) gcc 4.0 bug #623
     T instantiated_first (T);
+
+    // same as above but also referenced by another member of this class 
+    T instantiated_first_and_referenced (T) const;
 };
 
 #if defined (INSTANTIATE_TEMPLATE)
+
 template int instantiated_before_defined (int);
 template struct InstantiatedBeforeDefined<int>;
-#endif   // INSTANTIATE_TEMPLATE
+
+#elif defined (EXTERN_TEMPLATE)
+
+#  if __GNUG__ >= 3
+     // disable gcc 3.x (and beyond) error: ISO C++ forbids the use
+     // of `extern' on explicit instantiations
+#    pragma GCC system_header
+#  endif   // gcc >= 3
+
+extern template int instantiated_before_defined (int);
+extern template struct InstantiatedBeforeDefined<int>;
+
+#endif   // INSTANTIATE_TEMPLATE, EXTERN_TEMPLATE
 
 #if defined (INCLUDE_CC_FILE)
 #  include "instantiation_before_definition.cc"


Reply via email to