[cfe-commits] r148874 - in /cfe/trunk: lib/Sema/SemaExprCXX.cpp test/Analysis/reference.cpp

John McCall rjmccall at apple.com
Sat Jan 28 23:15:03 PST 2012


On Jan 28, 2012, at 10:38 PM, Nico Weber wrote:
> On Sat, Jan 28, 2012 at 4:50 PM, Chandler Carruth <chandlerc at google.com> wrote:
>> qualifying the pointer with volatile works, and is only a touch awkward.
>> We've already done this for one copy, I'll update the main open source
>> version as soon as I'm able.
> 
> You mean like
> 
> template <typename T>
> inline T Invalid() {
>  return *static_cast<volatile typename remove_reference<T>::type*>(0);
> }
> 
> ? If I then pass a type with a default copy constructor (say "class A
> {}; Invalid<A>();"), I get this error:

Does this function need to have a body at all?  It seems like a
metaprogramming function, and pure declarations generally suffice for those.

If it does need an actual body, it could just be "abort();" with no return
statement.  Anything else requires you to have a way to actually produce
a value of an arbitrary type from nothing, which is in general not
possible.  Even your old method is vulnerable to types with inaccessible
or deleted copy constructors.

John.



More information about the cfe-commits mailing list