[Bug libstdc++/98605] New: clang-tidy error parsing <mutex> on libstdc++-v3
mizvekov at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Jan 8 19:07:42 GMT 2021
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98605
Bug ID: 98605
Summary: clang-tidy error parsing <mutex> on libstdc++-v3
Product: gcc
Version: 10.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: mizvekov at gmail dot com
Target Milestone: ---
clang-tidy errors parsing `#include <mutex>` when _GLIBCXX_HAVE_TLS is not
defined, with the following message:
```
include/c++/mutex:738:7: error: use of undeclared identifier '__once_callable';
did you mean '__callable'? [clang-diagnostic-error]
__once_callable = nullptr;
^
include/c++/mutex:716:12: note: '__callable' declared here
auto __callable = [&] {
^
include/c++/mutex:739:7: error: use of undeclared identifier '__once_call'
[clang-diagnostic-error]
__once_call = nullptr;
^
```
This was caused by the following commit:
```
commit 018813c8994b7dceab1b7d999e9c09654a22ef50
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Fri Oct 13 12:56:07 2017 +0100
PR libstdc++/82481 Suppress clang-tidy warnings
PR libstdc++/82481
* include/std/mutex (call_once): Suppress clang-tidy warnings about
dangling references.
diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex
index 8c692a88ffd..50420ee22d4 100644
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -688,6 +688,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
__set_once_functor_lock_ptr(0);
#endif
+#ifdef __clang_analyzer__
+ // PR libstdc++/82481
+ __once_callable = nullptr;
+ __once_call = nullptr;
+#endif
+
if (__e)
__throw_system_error(__e);
}
```
The problem is that __once_callable et al are only declared when
_GLIBCXX_HAVE_TLS is defined.
A simple patch like this would fix it:
```
--- a/libstdc++-v3/include/std/mutex
+++ b/libstdc++-v3/include/std/mutex
@@ -731,9 +731,7 @@
#ifndef _GLIBCXX_HAVE_TLS
if (__functor_lock)
__set_once_functor_lock_ptr(0);
-#endif
-
-#ifdef __clang_analyzer__
+#elif defined(__clang_analyzer__)
// PR libstdc++/82481
__once_callable = nullptr;
__once_call = nullptr;
```
More information about the Gcc-bugs
mailing list