[llvm] r208388 - Remove use of = default/= delete as they're unsupported on MSVC2012

David Blaikie dblaikie at gmail.com
Thu May 8 20:11:56 PDT 2014


On Thu, May 8, 2014 at 8:06 PM, NAKAMURA Takumi <geek4civic at gmail.com> wrote:
> Thanks, David. I wondered how to introduce alternative of defaulted
> functions on that.
>
> We can add LLVM_DELETED_FUNCTION with "= delete". It'd be better to
> put deleted functions into private scope for deleted-unaware
> compilers, though.

The privacy isn't /too/ much of an issue. Yeah, it'd help people
developing on MSVC2012 to not break things (since they'd get a
compilation error instead of a linker error) but between buildbot
coverage and lots of developers using things that do support = delete,
it wouldn't be too much of a burden to fix/revert if/when the odd
MSVC2012-using developer introduced a call to them.

The short answer is, I think: don't bother. Just write out the special
members (don't use = default, do use = delete via
LLVM_DELETED_FUNCTION) until we drop MSVC2012 compatibility.

> Jordan, I wonder how to implement defaulted functions with macros...
>
> 1. Conditionalize
>
> #if LLVM_DEFAULTED_FUNCTION_AVAILABLE
>   MoveOnly(...) = default;
> #endif
>
> 2. Conditionalize with macro
>
> #define LLVM_DEFAULTED_FUNCTION(decl) decl = default /* or eliminate entirely */
>
>   LLVM_DEFAULTED_FUNCTION(MoveOnly(...));

This works only for those functions that don't actually require an
implementation... which is basically the default ctor and the dtor.
Not move/copy operations (which, if not defaulted, would need the
members to be enumerated to copy/move them)

>
> 3. Give the body to each functionality.
>
> #if !__has_feature(cxx_defaulted_functions)
> #  define LLVM_DEFAULTED_EMPTY_CONSTRUCTOR {}
> #  define LLVM_DEFAULTED_COPY_FUNCTION(arg) {*this = arg;}
> #endif
>
> 0. Ask C++ guru!
>
> 2014-05-09 11:26 GMT+09:00 David Blaikie <dblaikie at gmail.com>:
>> Author: dblaikie
>> Date: Thu May  8 21:26:36 2014
>> New Revision: 208388
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=208388&view=rev
>> Log:
>> Remove use of = default/= delete as they're unsupported on MSVC2012
>>
>> Modified:
>>     llvm/trunk/unittests/ADT/StringMapTest.cpp
>>
>> Modified: llvm/trunk/unittests/ADT/StringMapTest.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringMapTest.cpp?rev=208388&r1=208387&r2=208388&view=diff
>> ==============================================================================
>> --- llvm/trunk/unittests/ADT/StringMapTest.cpp (original)
>> +++ llvm/trunk/unittests/ADT/StringMapTest.cpp Thu May  8 21:26:36 2014
>> @@ -221,10 +221,15 @@ TEST_F(StringMapTest, NonDefaultConstruc
>>  struct MoveOnly {
>>    int i;
>>    MoveOnly(int i) : i(i) {}
>> -  MoveOnly(MoveOnly &&) = default;
>> -  MoveOnly(const MoveOnly &) = delete;
>> -  MoveOnly &operator=(MoveOnly &&) = default;
>> -  MoveOnly &operator=(const MoveOnly &) = delete;
>> +  MoveOnly(MoveOnly &&RHS) : i(RHS.i) {}
>> +  MoveOnly &operator=(MoveOnly &&RHS) {
>> +    i = RHS.i;
>> +    return *this;
>> +  }
>> +
>> +private:
>> +  MoveOnly(const MoveOnly &);
>> +  MoveOnly &operator=(const MoveOnly &);
>>  };
>>
>>  TEST_F(StringMapTest, MoveOnlyKey) {
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list