Uploaded image for project: 'SonarCFamily'
  1. SonarCFamily
  2. CPP-3255

S3743: FN when one of the throwing paths is not on the user side

    XMLWordPrintable

    Details

    • Type: False Negative
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 6.25
    • Fix Version/s: 6.26
    • Component/s: C++, Rules
    • Labels:
      None

      Description

      class MyException : public std::exception {};
      
      #include <filesystem>
      #include <exception>
      #include <string>
      
      void f2(const std::string& _pathToFile) {
        if (!_pathToFile.empty()) {
          throw MyException{};
        }
      }
      
      void g2() noexcept { // Error: Remove this "noexcept" clause on the function declaration as it can throw.
        f2("test");
      }
      
      void f1(const std::filesystem::path& _pathToFile) {
        if (std::filesystem::exists(_pathToFile)) {
          throw MyException{};
        }
      }
      
      void g1() noexcept { // FN: No issue is raised
        f1("test");
      }
      

      g1 can throw an exception in two different paths:

      • when calling std::filesystem::exists
      • throw MyException in f1

      The first path is not on the user side so we don't raise any issue at all, even though the second path is on the user side.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              amelie.renard Amélie Renard
              Reporter:
              amelie.renard Amélie Renard
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: