This is an archive of the discontinued LLVM Phabricator instance.

[libcxx] [test] Replace non-Standard "atomic_flag f(false);" with Standard "atomic_flag f;"
ClosedPublic

Authored by EricWF on Apr 29 2016, 6:48 PM.

Details

Summary

Replace non-Standard "atomic_flag f(false);" with Standard "atomic_flag f;" in clear tests.
Although the value of 'f' is unspecified it shouldn't matter because these tests always call f.test_and_set() without checking the result, so the initial state shouldn't matter.

The test init03.pass.cpp is explicitly testing this non-Standard extension; It has been moved into the test/libcxx directory.

Diff Detail

Event Timeline

STL_MSFT updated this revision to Diff 55700.Apr 29 2016, 6:48 PM
STL_MSFT retitled this revision from to [libcxx] [test] Replace non-Standard "atomic_flag f(false);" with Standard "atomic_flag f = ATOMIC_FLAG_INIT;"..
STL_MSFT updated this object.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.
EricWF edited edge metadata.May 2 2016, 12:13 PM

This is a small problem. We actually provide <atomic> in C++03 minus ATOMIC_FLAG_INIT since it requires C++11.
I'll come up with a way to fix these tests so they keep working in C++03.

Since you control the definition of ATOMIC_FLAG_INIT, can you make it something like __secret_tag_type() in C++03? That would allow you to continue to provide the atomic_flag(bool) extension in C++03.

I actually want this form of initialization to break in C++03, From the original review:

After putting this question up on cfe-dev I have decided that it would be best to allow the use of <atomic> in C++03. Although static initialization is a concern the syntax required to get it is C++11 only. Meaning that C++11 constant static initialization cannot silently break in C++03, it will always cause a syntax error. Furthermore ATOMIC_VAR_INIT and ATOMIC_FLAG_INIT remain defined in C++03 even though they cannot be used because C++03 usages will cause better error messages.

I think I'll just hack up these tests, or make them require C++11 or greater and add C++03 specific tests elsewhere.

Makes sense. MSVC will never have C++03 or C++11 modes (only 14/17/future) so anything you do in C++03 mode is fine by me.

EricWF commandeered this revision.May 2 2016, 5:00 PM
EricWF edited reviewers, added: STL_MSFT; removed: EricWF.

Stealing this review from STL.

EricWF updated this revision to Diff 55920.May 2 2016, 5:05 PM
EricWF retitled this revision from [libcxx] [test] Replace non-Standard "atomic_flag f(false);" with Standard "atomic_flag f = ATOMIC_FLAG_INIT;". to [libcxx] [test] Replace non-Standard "atomic_flag f(false);" with Standard "atomic_flag f;" .
EricWF updated this object.

@STL_MSFT Does this work for you? I simply removed the initializer and call the default constructor instead. This leaves 'f' in an unspecified state but that shouldn't matter because we always call 'f.test_and_set()' before testing the clear operation.

STL_MSFT edited edge metadata.May 2 2016, 5:58 PM

I think this will work for me. Thanks!

This revision was automatically updated to reflect the committed changes.