[Bug c++/16174] [3.4/3.5 Regression] deducing top-level consts

giovannibajo at libero dot it gcc-bugzilla@gcc.gnu.org
Fri Jun 25 01:08:00 GMT 2004


------- Additional Comments From giovannibajo at libero dot it  2004-06-25 01:06 -------
Nathan,

there is something I don't understand here, and with your patch. This is what 
should happen in my opinion:

- We try to instantiate the declaration of the templated copy ctor to add it to 
the overload set.
- We deduce U = K<int> (no const here!) from the first parameter
- We substitute U into the non deduced context (second parameter). This causes 
the instantiation of A<K<int> > (still no const).
- A<K<int> > matches the general template (not the specialization), which is 
incomplete. This triggers SFINAE.
- The declaration we were trying to instantiate is discarded and not added to 
the overload set.

Instead, if you have code like this:

void bar(void)
{
  const K<int> a;
  K<int> b(a);
}

the deduction will find U = K<int> const, and it will trigger the instantiation 
of A<K<int> const>. Whild doing so, we would be trying to access 
K<int>::compile_time_error which does not exist, and this is not SFINAE 
anymore! A diagnostic will be emitted and compilation is aborted.

The whoel point is that K is actually auto_ptr<>, and it is forbidden to do a 
cctor from a const auto_ptr<> (because it would effectively modify it, given 
the semantic of the pointer). This smart trick allows to detect and reject such 
situations.

If I'm reading your patch correctly, you are making so that 
instantiate_template also falls under SFINAE. This would prevent the function 
bar() above from emitting a diagnostic, and would make the whole trick totally 
useless.

I think I read a DR where John Spicer was saying that it is unfeasable to shut 
all the possible errors that could be emitted during (possibly cascaded)
template instantiations for the sake of SFINAE. In fact, this is what EDG does. 
If you try it on g++.old-deja/g++.pt/crash30.C, it will emit diagnostic also on 
the line where you removed the dg-error.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16174



More information about the Gcc-bugs mailing list