<div dir="ltr">Hi,<div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">2014-08-03 18:33 GMT+02:00 Arthur O'Dwyer <span dir="ltr"><<a href="mailto:arthur.j.odwyer@gmail.com" target="_blank">arthur.j.odwyer@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Does this reject valid C++ code involving templates? I.e., is there<br>
any wording in the Standard that says this kind of code *can* be<br>
rejected, or are these declarations expected to compile quietly?<br>
<br></blockquote><div><br></div><div>No, it doesn't, the following code isn't rejected by the clang after applying my patch:</div><div><br></div><div><br></div><div> 1</div><div> 2 struct C</div><div> 3 {</div>
<div><br></div><div> 4 typedef C type;</div><div> 5 virtual void foo() = 0;</div><div> 6 };</div><div> 7 </div><div> 8 template<class T></div><div> 9 struct X</div><div> 10 {</div><div><br></div><div>
11 typename T::type mytype();</div>
<div> 12 }; </div><div><br></div><div><br></div><div><br></div><div>It's hard to reject that as, AFAIK, we can look into dependent type at this point (but I'm not sure of that).</div><div><br></div><div><br></div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><br>
I don't see anything wrong with returning an instance of an abstract<br>
type, in principle. The type system shouldn't care about that sort of<br>
thing.<br>
<br></blockquote><div><br></div><div><div>The standard states that "An abstract class shall not be used as a parameter type, as a function return type, or as the type of an explicit conversion" (found this in January 2012 draft, class.abstract $10.4.3)</div>
<div><br></div><div>This patch is the easiest way to fix the problem. Probably, I could try to fix it other way, but then I would need to hunt for some special cases, e.g:</div><div><br></div><div> 1 struct A {</div><div>
2 virtual int f() = 0;</div><div> 3 };</div><div> 4 </div><div> 5 struct C : A</div><div> 6 {</div><div> 7 virtual int f() { return 5; }</div><div> 8 };</div><div> 9 </div><div> 10 struct B {</div><div>
11 A f() { C a; return a;}</div><div> 12 };</div><div> 13 </div><div> 14 int main()</div><div> 15 {</div><div> 16 B b;</div><div> 17 b.f();</div><div> 18 return 0;</div><div> 19 }</div><div><br></div><div>
<br></div><div>Br,<br></div></div><div>Robert Matusewicz</div><div><br></div></div></div></div>