Wrong clang-tidy warning about static global lambda variables?
Provided the following code, in the global scope, clang-tidy gives no warning:
auto test = {};
However, when doing the following, it does:
#include <tuple>
auto test = {
std::tuple t{1, 2, 3};
};
<source>:3:6: warning: initialization of 'test' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
auto test = {
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/tuple:646:19: note: possibly throwing constructor declared here
constexpr tuple(_UElements&&... __elements)
^
Marking the lambda as noexcept
doesn't help.
However, I don't see why that would be a problem. The exception could only theorically happen when invoking the lambda, wouldn't it?
The following code does not cause the warning to appear:
auto test = {
throw 0;
};
Is clang-tidy wrong, or did I miss something?
c++ lambda clang-tidy
add a comment |
Provided the following code, in the global scope, clang-tidy gives no warning:
auto test = {};
However, when doing the following, it does:
#include <tuple>
auto test = {
std::tuple t{1, 2, 3};
};
<source>:3:6: warning: initialization of 'test' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
auto test = {
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/tuple:646:19: note: possibly throwing constructor declared here
constexpr tuple(_UElements&&... __elements)
^
Marking the lambda as noexcept
doesn't help.
However, I don't see why that would be a problem. The exception could only theorically happen when invoking the lambda, wouldn't it?
The following code does not cause the warning to appear:
auto test = {
throw 0;
};
Is clang-tidy wrong, or did I miss something?
c++ lambda clang-tidy
add a comment |
Provided the following code, in the global scope, clang-tidy gives no warning:
auto test = {};
However, when doing the following, it does:
#include <tuple>
auto test = {
std::tuple t{1, 2, 3};
};
<source>:3:6: warning: initialization of 'test' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
auto test = {
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/tuple:646:19: note: possibly throwing constructor declared here
constexpr tuple(_UElements&&... __elements)
^
Marking the lambda as noexcept
doesn't help.
However, I don't see why that would be a problem. The exception could only theorically happen when invoking the lambda, wouldn't it?
The following code does not cause the warning to appear:
auto test = {
throw 0;
};
Is clang-tidy wrong, or did I miss something?
c++ lambda clang-tidy
Provided the following code, in the global scope, clang-tidy gives no warning:
auto test = {};
However, when doing the following, it does:
#include <tuple>
auto test = {
std::tuple t{1, 2, 3};
};
<source>:3:6: warning: initialization of 'test' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
auto test = {
^
/opt/compiler-explorer/gcc-8.2.0/lib/gcc/x86_64-linux-gnu/8.2.0/../../../../include/c++/8.2.0/tuple:646:19: note: possibly throwing constructor declared here
constexpr tuple(_UElements&&... __elements)
^
Marking the lambda as noexcept
doesn't help.
However, I don't see why that would be a problem. The exception could only theorically happen when invoking the lambda, wouldn't it?
The following code does not cause the warning to appear:
auto test = {
throw 0;
};
Is clang-tidy wrong, or did I miss something?
c++ lambda clang-tidy
c++ lambda clang-tidy
edited Nov 25 '18 at 14:42
Asu
asked Nov 25 '18 at 13:21
AsuAsu
1,4861122
1,4861122
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The Clang-Tidy warning is about the construction of the global variable, not about the operator()
of such class does. Hence, this looks like a false positive.
I would make the variable constexpr
as it can't change during the lifetime of your program. That should as well suppress the warning as well as constexpr can't be done of such an exception is thrown.
PS: You can log bugs for Clang-Tidy at bugs.llvm.org
Actually... Withconstexpr
it still actually warns. I will report it to LLVM then, thanks!
– Asu
Nov 25 '18 at 17:10
Sounds like a second bug :)
– JVApen
Nov 25 '18 at 17:14
Reported both: the lambda issue and the constexpr issue
– Asu
Nov 25 '18 at 18:07
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467901%2fwrong-clang-tidy-warning-about-static-global-lambda-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The Clang-Tidy warning is about the construction of the global variable, not about the operator()
of such class does. Hence, this looks like a false positive.
I would make the variable constexpr
as it can't change during the lifetime of your program. That should as well suppress the warning as well as constexpr can't be done of such an exception is thrown.
PS: You can log bugs for Clang-Tidy at bugs.llvm.org
Actually... Withconstexpr
it still actually warns. I will report it to LLVM then, thanks!
– Asu
Nov 25 '18 at 17:10
Sounds like a second bug :)
– JVApen
Nov 25 '18 at 17:14
Reported both: the lambda issue and the constexpr issue
– Asu
Nov 25 '18 at 18:07
add a comment |
The Clang-Tidy warning is about the construction of the global variable, not about the operator()
of such class does. Hence, this looks like a false positive.
I would make the variable constexpr
as it can't change during the lifetime of your program. That should as well suppress the warning as well as constexpr can't be done of such an exception is thrown.
PS: You can log bugs for Clang-Tidy at bugs.llvm.org
Actually... Withconstexpr
it still actually warns. I will report it to LLVM then, thanks!
– Asu
Nov 25 '18 at 17:10
Sounds like a second bug :)
– JVApen
Nov 25 '18 at 17:14
Reported both: the lambda issue and the constexpr issue
– Asu
Nov 25 '18 at 18:07
add a comment |
The Clang-Tidy warning is about the construction of the global variable, not about the operator()
of such class does. Hence, this looks like a false positive.
I would make the variable constexpr
as it can't change during the lifetime of your program. That should as well suppress the warning as well as constexpr can't be done of such an exception is thrown.
PS: You can log bugs for Clang-Tidy at bugs.llvm.org
The Clang-Tidy warning is about the construction of the global variable, not about the operator()
of such class does. Hence, this looks like a false positive.
I would make the variable constexpr
as it can't change during the lifetime of your program. That should as well suppress the warning as well as constexpr can't be done of such an exception is thrown.
PS: You can log bugs for Clang-Tidy at bugs.llvm.org
answered Nov 25 '18 at 16:49
JVApenJVApen
5,41711238
5,41711238
Actually... Withconstexpr
it still actually warns. I will report it to LLVM then, thanks!
– Asu
Nov 25 '18 at 17:10
Sounds like a second bug :)
– JVApen
Nov 25 '18 at 17:14
Reported both: the lambda issue and the constexpr issue
– Asu
Nov 25 '18 at 18:07
add a comment |
Actually... Withconstexpr
it still actually warns. I will report it to LLVM then, thanks!
– Asu
Nov 25 '18 at 17:10
Sounds like a second bug :)
– JVApen
Nov 25 '18 at 17:14
Reported both: the lambda issue and the constexpr issue
– Asu
Nov 25 '18 at 18:07
Actually... With
constexpr
it still actually warns. I will report it to LLVM then, thanks!– Asu
Nov 25 '18 at 17:10
Actually... With
constexpr
it still actually warns. I will report it to LLVM then, thanks!– Asu
Nov 25 '18 at 17:10
Sounds like a second bug :)
– JVApen
Nov 25 '18 at 17:14
Sounds like a second bug :)
– JVApen
Nov 25 '18 at 17:14
Reported both: the lambda issue and the constexpr issue
– Asu
Nov 25 '18 at 18:07
Reported both: the lambda issue and the constexpr issue
– Asu
Nov 25 '18 at 18:07
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467901%2fwrong-clang-tidy-warning-about-static-global-lambda-variables%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown