[libcxx-commits] [PATCH] D115995: [libcxx] Add deprecation notices to macros deprecated in P0883R2

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 21 17:47:45 PST 2021


Quuxplusone added a comment.

In D115995#3205377 <https://reviews.llvm.org/D115995#3205377>, @tambre wrote:

> In D115995#3205319 <https://reviews.llvm.org/D115995#3205319>, @Quuxplusone wrote:
>
>> Okay, now that I'm hitting this in a real codebase, I'm stumped as to what the (WG21 and/or libc++) recommendation is, here. `ATOMIC_FLAG_INIT` is //required// up-to-and-including C++17, and then //deprecated// in-and-above C++20? So if I have code in my codebase today like
>
> I don't see why you'd think using the macro would be required.

AFAICT, on paper, C++17/20 `atomic_flag` has no constructors
https://en.cppreference.com/w/cpp/atomic/atomic_flag/atomic_flag
except for the default constructor (trivial in C++17) and the deleted copy constructor. So if you want an `atomic_flag` initialized with `false`, you need //some// way of getting `false` into it. On paper, there's no guarantee that `std::atomic_flag f = {false};` will compile. But I just checked Godbolt and every major compiler //does// support that syntax, so I suppose it's safe to use in practice: https://godbolt.org/z/4cbbGcv96

> Explicitly init to `false`. If C++20 and higher, then you can rely on the default constructor.

Yeah, the default ctor definitely works in C++20-and-above. Below C++20, the default ctor is on-paper "guaranteed" to be trivial and thus "guaranteed" //not to work//; but it looks like implementations largely ignore that, too, AFAICT, and just do the C++20 thing everywhere (plus the extra constructor from `bool` which is super helpful).

Anyway, I've added `-Wno-deprecated-pragma` to my build flags for now; that's not as terrible-feeling a workaround as I was worried it would be. And ultimately we'll probably just use the `atomic_flag(bool)` ctor, even though (AFAICT) it's //technically// an extension.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115995/new/

https://reviews.llvm.org/D115995



More information about the libcxx-commits mailing list