Wrong clang-tidy warning about static global lambda variables?












5















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?










share|improve this question





























    5















    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?










    share|improve this question



























      5












      5








      5








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 25 '18 at 14:42







      Asu

















      asked Nov 25 '18 at 13:21









      AsuAsu

      1,4861122




      1,4861122
























          1 Answer
          1






          active

          oldest

          votes


















          1














          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






          share|improve this answer
























          • 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











          • Reported both: the lambda issue and the constexpr issue

            – Asu
            Nov 25 '18 at 18:07











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          1














          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






          share|improve this answer
























          • 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











          • Reported both: the lambda issue and the constexpr issue

            – Asu
            Nov 25 '18 at 18:07
















          1














          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






          share|improve this answer
























          • 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











          • Reported both: the lambda issue and the constexpr issue

            – Asu
            Nov 25 '18 at 18:07














          1












          1








          1







          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






          share|improve this answer













          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







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 16:49









          JVApenJVApen

          5,41711238




          5,41711238













          • 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











          • 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











          • 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


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

          Calculate evaluation metrics using cross_val_predict sklearn

          Insert data from modal to MySQL (multiple modal on website)