[cfe-commits] r105309 - /cfe/trunk/www/cxx_compatibility.html

John McCall rjmccall at apple.com
Tue Jun 1 18:26:33 PDT 2010

Author: rjmccall
Date: Tue Jun  1 20:26:32 2010
New Revision: 105309

URL: http://llvm.org/viewvc/llvm-project?rev=105309&view=rev
Add a compatibility note about incomplete types in templates.


Modified: cfe/trunk/www/cxx_compatibility.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_compatibility.html?rev=105309&r1=105308&r2=105309&view=diff
--- cfe/trunk/www/cxx_compatibility.html (original)
+++ cfe/trunk/www/cxx_compatibility.html Tue Jun  1 20:26:32 2010
@@ -25,6 +25,7 @@
 <li><a href="#init_static_const">Initialization of non-integral static const data members within a class definition</a></li>
 <li><a href="#dep_lookup">Unqualified lookup in templates</a></li>
 <li><a href="#dep_lookup_bases">Unqualified lookup into dependent bases of class templates</a></li>
+<li><a href="#undep_incomplete">Incomplete types in templates</a></li>
 <li><a href="#bad_templates">Templates with no valid instantiations</a></li>
 <li><a href="#default_init_const">Default initialization of const variable of a class type requires user-defined default constructor</a></li>
@@ -215,6 +216,37 @@
 <!-- ======================================================================= -->
+<h2 id="undep_incomplete">Incomplete types in templates</h2>
+<!-- ======================================================================= -->
+The following code is invalid, but compilers are allowed to accept it:
+  class IOOptions;
+  template <class T> bool read(T &value) {
+    IOOptions opts;
+    return read(opts, value);
+  }
+  class IOOptions { bool ForceReads; };
+  bool read(const IOOptions &opts, int &x);
+  template bool read<>(int &);
+The standard says that types which don't depend on template parameters
+must be complete when a template is defined if they affect the
+program's behavior.  However, the standard also says that compilers
+are free to not enforce this rule.  Most compilers enforce it to some
+extent; for example, it would be an error in GCC to
+write <tt>opts.ForceReads</tt> in the code above.  In Clang, we feel
+that enforcing the rule consistently lets us provide a better
+experience, but unfortunately it also means we reject some code that
+other compilers accept.
+<p>We've explained the rule here in very imprecise terms; see
+[temp.res]p8 for details.
+<!-- ======================================================================= -->
 <h2 id="bad_templates">Templates with no valid instantiations</h2>
 <!-- ======================================================================= -->

More information about the cfe-commits mailing list