C++ Logo

sg10

Advanced search

Re: [SG10] How closely should our recommendation match clang?

From: John Spicer <jhs_at_[hidden]>
Date: Sat, 26 Jan 2013 07:36:22 -0500
On Jan 25, 2013, at 12:23 PM, Nelson, Clark wrote:

>>> But the point of the conditional compilation is presumably that there
>> is a way for the program to do its job without the new feature. A
>> program that is simply written to require the new feature doesn't need
>> conditional compilation at all; it can just try to use the new feature,
>> and fail to compile if it isn't available.
>>
>> But it will not do the right thing when the feature is present. This
>> can cause bad outcomes because of ODR violations if combined with code
>> from another compiler.
>
> Mixing code from different from different compilers is something that is certainly beyond the scope of the standard, but let's talk about it anyway, at least for a bit. Can you present an example of code that would produce the kind of bad outcome that concerns you?
>

The specific issue of how to mix code is beyond the scope of the standard, but trying to make sure the standard meets users needs in the real world is not beyond the scope of our design goals (for example, not selecting new keywords that are in common use).

If two compilers have rvalue references and move constructors, but only one defines the macro, the body of inline function f will be different between implementations. This is a trivial example -- you can come up with similar cases for just about any language feature.

John.

// assume this part came from a header file
struct X {
        int i;
        X() : i(0) {}
        X(const X& x){ i = x.i;}
#if __has_move_or_rvalue_refs_or_something
        X(X&& x){ i = x.i;}
#endif
};

inline X f(X x) { return x; }

// this part is in a source file

int main() {
        X x;
        X x2 = f(x);
}

Received on 2013-01-26 13:36:26