[llvm] r230010 - Make the static instance of None just const.

David Blaikie dblaikie at gmail.com
Fri Feb 20 09:52:09 PST 2015


On Fri, Feb 20, 2015 at 9:43 AM, Justin Bogner <mail at justinbogner.com>
wrote:

> David Blaikie <dblaikie at gmail.com> writes:
> > On Fri, Feb 20, 2015 at 5:16 AM, Benjamin Kramer <
> benny.kra at googlemail.com>
> > wrote:
> >
> >     Author: d0k
> >     Date: Fri Feb 20 07:16:05 2015
> >     New Revision: 230010
> >
> >     URL: http://llvm.org/viewvc/llvm-project?rev=230010&view=rev
> >     Log:
> >     Make the static instance of None just const.
> >
> >     This way there shouldn't be any unused variable warnings.
> >
> >     Modified:
> >         llvm/trunk/include/llvm/ADT/None.h
> >
> >     Modified: llvm/trunk/include/llvm/ADT/None.h
> >     URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/
> >     None.h?rev=230010&r1=230009&r2=230010&view=diff
> >
>  ==========================================================================
> >     ====
> >     --- llvm/trunk/include/llvm/ADT/None.h (original)
> >     +++ llvm/trunk/include/llvm/ADT/None.h Fri Feb 20 07:16:05 2015
> >     @@ -20,7 +20,7 @@ namespace llvm {
> >      /// \brief A simple null object to allow implicit construction of
> >     Optional<T>
> >      /// and similar types without having to spell out the
> specialization's
> >     name.
> >      enum class NoneType { None };
> >
> > At this point NoneType could just be an opaque/trivial struct instead of
> an
> > enum class?
> >
> >
> >     -static NoneType None;
> >     +const NoneType None = None;
> >
> > Does this result in ODR violations? (either because None is not defined
> in the
> > program at all and it is ODR used, or because this is a definition (?)
> and
> > it's in multiple translation units? - I always forget which)
>
> This should be fine. NoneType "satisfies the requirements for appearing
> in a constant expression", so based on [basic.def.odr].3 I don't think
> None will ever be odr-used. This should also mean that your idea of
> making this constexpr should be strictly clearer and equivalent.
>

Ah, thanks for finding the right chapter & verse.

The full wording is:

"A variable whose name appears as a potentially-evaluated expression is
odr-used unless it is an object that satisfies the requirements for
appearing in a constant expression (5.19) and the lvalue-to-rvalue
conversion (4.1) is immediately applied."

That latter requirement ("the lvalue-to-rvalue conversion is immediately
applied") may be problematic, especially with regards to perfect forwarding.

It's possible we'd still need a definition if anyone did, say, this:

struct foo {
foo(ArrayRef<T>);
};
...
make_unique<foo>(None);

Because then the None value would be perfectly forwarded (which means
taking a reference to it) through to foo's ctor...

I think I'm still confusing myself at various points, because I can't quite
make heads-or-tails of the behavior I'm seeing in a few experiments. Maybe
it is just doing the right thing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150220/33c61769/attachment.html>


More information about the llvm-commits mailing list