Coder Social home page Coder Social logo

oclint / oclint Goto Github PK

View Code? Open in Web Editor NEW
3.7K 3.7K 487.0 1.79 MB

A static source code analysis tool to improve quality and reduce defects for C, C++ and Objective-C

Home Page: http://oclint.org

License: BSD 3-Clause "New" or "Revised" License

C++ 92.12% Python 5.01% Shell 0.14% CMake 2.64% C 0.09%

oclint's Introduction

GitHub Actions Status Coverage Status

OCLint is a static code analysis tool for improving quality and reducing defects by inspecting C, C++ and Objective-C code.

It looks for potential problems that aren't visible to compilers, for example:

  • Possible bugs - empty if/else/try/catch/finally statements
  • Unused code - unused local variables and parameters
  • Complicated code - high cyclomatic complexity, NPath complexity and high NCSS
  • Redundant code - redundant if statement and useless parentheses
  • Code smells - long method and long parameter list
  • Bad practices - inverted logic and parameter reassignment
  • ...

For more information, visit https://oclint.org

oclint's People

Contributors

aleffert avatar arnaudgelas avatar bok avatar chrta avatar daniel-beard avatar danyspin97 avatar doug-w avatar dymv avatar fldxo avatar goxberry avatar hinterwaeldlers avatar interstateone avatar jarod42 avatar joekain avatar kazuhidet avatar kronenthaler avatar lqi avatar maplesteve avatar marcelotrevisani avatar mbitsnbites avatar mgu avatar mwitaszekdmi avatar nik3212 avatar nschum avatar queengooborg avatar ryuichis avatar smoofra avatar sylvestre avatar unrealquester avatar yachoor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

oclint's Issues

Code errors cause Error in Processing file

XCode 4.5.1
OSX 10.8.3
OCLint 0.7 (built from last commit: 02a53e5)

First let me thank you for all your hard work on this awesome tool Longyi, it is a service to us all and we really appreciate your time.

I am having a really odd problem, and I think this is a genuine bug in the code.

DESCRIPTION:

When analyzing .m file that contains a bad logical coding error, OCLint identifies the error, but then dies with a "Error while processing file" message.


STEPS TO REPRODUCE:

  1. Analyze a project with a code file with a mismatched enum error.

ACTUAL BEHAVIOR:

OCLint outputs an explanation of all coding errors to the console, but then dies and writes no pmd output file.

EXPECTED BEHAVIOR:

OCLint should complete normally, and write the pmd output report.


The error has to do with a programmer mistakenly casting the input to a method as a certain typedef enum, and then comparing it against the values of another typedef enum. I commented out the offending lines of code, and voila, everything works as expected. pmd output and all.

Let me know if I can provide more information, am attempting to prepare a sanitized test project that might demonstrate the issue.

PMD reporter crashes

Hi

I am trying to get the current git version running on a Suse 12.1 system, and it crashes. All I get is the following command output:

oclint-0.8: <shorted_path>/llvm/include/llvm/Support/Casting.h:97: static bool llvm::isa_impl_cl<To, const From*>::doit(const From*) [with To = clang::DeclStmt, From = clang::Stmt]: Assertion `Val && "isa<> used on a null pointer"' failed.

Command line for call was:

oclint-json-compilation-database -- --report-type pmd -o ../output.xml

The json output was generated by cmake 2.8.11

Anyone got an idea? Would be much appreciated

kind regards,
Roland

Exclude multiple classes from oclint-json-compilation-database?

This is a question about command line usage: I would like to exclude a number of filename patterns from the final report, and I'm not having much luck figuring out how to send in a list of patterns to the -e (-exclude) argument of oclint-json-compilation-database.

Here is a scratch example what I'm trying to do (I've also tried many other combinations of syntax):
-exclude=JSONKit.m,Test,Debug.m

Can you provide a simple usage example that would let me exclude say 2-3 patterns?

Apply rules concurrently

We would like to have the option to apply rules concurrently against translation units. This should be able to improve the performance largely.

Organizing Results for Better Reporting

After all violations emitted and collected into Results, we need to organize the violation set better consumable for reporters.

For example,

  • Remove duplicated violations
  • Ordering
  • Grouping

Some notes about removing duplicated violations. Same source, although compiled with different compiler flags in the same oclint invocation, might result in duplicated violations. Duplication is perfectly fine inside Results, because we need to preserve the raw analysis results. However, duplication in reports could result in useful information sinking under duplications. Thus, removing duplicated violations is a must-have for reporting.

We could also then remove the existing logic for aggregating violation sets into vector of violations from current Results class to make core module more lightweight.

Having Clang Static Analyzer results in report

We have seen questions posted online like what's the reason to use oclint instead of clang static analyzer.

First of all, they are not competing each other. oclint IS a clang tooling based tool. Both clang static analyzer and oclint runs on top of the same intermediate representation of your source code. We sincerely appreciate the great work provided by LLVM/clang community. And in addition, we would like to contribute back as much as we could. For example, we are looking at the evaluation of a variable to understand whether it's always constant, we need a smarter one badly in some of our rules, and it helps the compiler to have a more concrete understanding as well.

Nobody wants to reinvent the wheels, so other than what clang static analyzer already provides, oclint focuses more on the perspective of code quality, we provide more rules in the areas of complexity, method sizes, programing practices, etc. You have awesome clang static analyzer to ensure your code is good and stable, and we hope to help to make your code better, cleaner, easier to understand, and artistic.

However, we have heard your pain of maintaining so many tools. Then why not having your favorite clang static analyzer results inside oclint reports, and clearly mark them as clang static analyzer result, so that you can relieve from having to maintain many tools, and you could have all the information you need from one place.

DeadCodeRule false positive on switch statements

case 3 in the following code is reported as dead code, but it's a false positive.

switch (option)
{
    case 1:
        doSomething();
        break;
    case 2:
        doFoo();
        return -1;
    case 3:
        doBar();
        return -2;
    ...
}

Error while processing <file_path>

I followed the doc up to the step where you generate a compile_commands.json file.
I then run oclint-json-compilation-database -v, and it fails to produce any report.

For each file of the project, a line is added at the end of the output in the console:

Error while processing <file_path>

One tidbit that might be useful buried in the long output by oclint is:
error: unable to handle compilation, expected exactly one compiler job in

As there is no more details along the error, I don't know what's missing / broken or invalid in my files.

Running this on Mac OS X 10.8.2, on a Objective-C project, with oclint current stable release (0.6).

empty if statement rule duplicates clang warning

Given:

if (cond) ;

I get the following with clang (current svn tip):

warning: if statement has empty body [-Wempty-body]
    if (cond) ;
              ^

as well as the oclint output:

empty if statement P2

The oclint rule is duplicating what clang itself is providing and clang provides better contextual information on the problem. Therefore, the oclint rule should be removed as it is redundant (unless you are going to duplicate all the other clang warnings).

oclint does not build. bits/c++config.h not found.

I try to build oclint using ./make. LLVM builds correctly but the oclint build stops with error.

'bits/c++config.h' file not found.

What did I wrong?

I'm using the git version from 2013-09-18 (today).

Error output:
-- The C compiler identification is Clang 3.4.0
-- The CXX compiler identification is Clang 3.4.0
-- Check for working C compiler: /home/x/support/oclint/build/llvm-install/bin/clang
-- Check for working C compiler: /home/x/support/oclint/build/llvm-install/bin/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /home/x/support/oclint/build/llvm-install/bin/clang++
-- Check for working CXX compiler: /home/x/support/oclint/build/llvm-install/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/x/support/oclint/build/oclint-core
Scanning dependencies of target OCLintCore
Scanning dependencies of target OCLintRuleSet
[ 14%] Building CXX object lib/CMakeFiles/OCLintRuleSet.dir/RuleConfiguration.cpp.o
In file included from /home/x/support/oclint/oclint-core/lib/RuleConfiguration.cpp:1:
/usr/lib/gcc/i686-linux-gnu/4.7/../../../../include/c++/4.7/cstdlib:43:10: fatal error: 'bits/c++config.h' file not found

include <bits/c++config.h>

     ^

1 error generated.

My machine:
Linux x 3.8.0-29-generic #42-Ubuntu SMP Tue Aug 13 23:12:18 UTC 2013 i686 i686 i686 GNU/Linux

Accept vector as value in RuleConfiguration

Currently, RuleConfiguration has a key/value type structure, and accept string type as keys, and int, double and string types as values.

In addition to them, we would like to accept vector type as values. For example, we should allow inputs like

oclint -rc foo=bar1 -rc foo=bar2 -rc foo=bar3

And we save all bar1, bar2, and bar3 into a vector, and retrieve them from rules.

We also need to consider the back-compatibility. For existing configurations, like CYCLOMATIC_COMPLEXITY, if multiple values are given to this key, when cyclomatic complexity rule tries to fetch this value, the last passed value should be returned. For example,

oclint -rc CYCLOMATIC_COMPLEXITY=20 -rc CYCLOMATIC_COMPLEXITY=15

Then inside a rule, when ask the value for CYCLOMATIC_COMPLEXITY, 15 should be returned.

oclint-json-compilation-databse

Hi,

If I create an XCode project with a space in the name (and thus in the filepath) oclint-json-compilation-database/oclint doesn't seem to work properly (but the code compiles fine using xcodebuild).

More specifically.

/tools/bin/oclint-0.7 "/Users/jon/Projects/A Project With A Space In It/A Project With A Space In It//MPTestClass.m"

Fails with the output.

LLVM ERROR: Cannot chdir into ""/Users/jon/Projects/A Project With A Space In It"

Better Suppress

We introduced suppress warnings in 0.7 release. Based on the experiments and feedback, there are spaces that we could make it better.

  1. Currently, the annotation is bound to a particular declaration that you want to suppress the warning. In other words, for each warning to be suppressed, one annotation needs to be added to the declaration. This is a lot of extra and unnecessary work. We hope to improve this by extending the effect scope of an annotation to the same semantic context as the associated declaration. For example, if __attribute__((annotate("oclint:suppress[unused local variable]"))) is bound to a method instead of a particular local variable, then all local variables inside this method need to be skipped no matter they are used or not. Similarly, when __attribute__((annotate("oclint"))) is applied to a class declaration, then we should like to simply suppress all warnings inside this class.
  2. There are instances that we just want to suppress the warnings of a particular line of code. So, adding a comment to that line and communicate with oclint is another simple and practical approach. For example, when a particular unused local variable is meant to be unused, then we might have something like int unusedVariable = 1; //NOLINT
  3. For adding suppress support to rules, currently, we have to modify the implementation of rules. This is a open-close principle violation. We would like to support this in a lower level, so that all existing rules and new introduced rules will get this by default.

Error with bundle with python 3.3

Traceback (most recent call last):
  File "bundle", line 12, in <module>
    from oclintscripts import version
ImportError: cannot import name version

it works correctly with python 2.7

To fix it (work with 2.7 and 3.3), I replace in oclintscripts/version.py
import path
by
import oclintscripts.path as path

Debug Output

It's good to have some intermediate output when debug flag is enabled. It outputs the progress of each compilation, pre-processing, analysis, and reporting steps.

For projects with a large code base, it gives confidence to developers with the status of the tool.

When things go wrong, it could help us narrow down the scope that should be looked at.

oclint locks up in some cases(friend usage and operator<<)

When calling oclint with the given file it locks and never ends.

I'm using oclang revision 7b89c4e with llvm revision 186082.

File:

#include <ostream>

//This locks oclint when executing "oclint <FILENAME> -- -c"

//Uncomment the function declaration and class forward declaration to make it work!
//Or uncomment one frient declaration
//Or remove the shift operation in blockOclint()


//class Foo;
//std::ostream& operator << (std::ostream& os, const Foo& foo);


class Foo
{
    public:
        friend std::ostream& operator << (std::ostream& os, const Foo& foo);
};


class Bar
{
    private:
        friend std::ostream& operator << ( std::ostream& os, const Foo& foo);
};

enum enum_t
{
};


void lockOclint()
{
    enum_t value;
    int a = value << 4;
}

Debug Emitting Message Enhancement

There are some heady methods can be added to Debug, some ideas like debug::emitLine appends \n to the message, debug::emit takes varargs, etc.

Put OCLint Documentation on GitHub

It would be very beneficial to OCLint if the project's documentation were on GitHub so that users can fork, edit, and pull request the docs. For example, there are many English mistakes in the getting started guide that I could fix. This would also allow the community to provide documentation more quickly. Poor documentation has been a weak point of OCLint for a long time.

unnecessarily slow clang compile

When I follow installation instructions it says I should run:
./buildClang.sh release

...but that doesn't seem to use all my cores at 100%? How can I pass a proper -j flag down to the actual build so it will run faster? And please make such parallel build the default as well.

Duplicated Matchers

Matchers are registered to the pool each time one matcher rule is applied, but never removed from the collection. This means, for a project with multiple files, when matcher rule is applied to the N-th file, same matchers are added to the pool N times. This results in duplicated violations.

Detail discussions can be found at https://groups.google.com/forum/#!topic/oclint-users/8GrE2rX3l0s

One solution:

diff --git a/oclint-rules/include/oclint/AbstractASTMatcherRule.h b/oclint-rules/include/oclint/AbstractASTMatcherRule.h
index 7985345..83541a5 100644
--- a/oclint-rules/include/oclint/AbstractASTMatcherRule.h
+++ b/oclint-rules/include/oclint/AbstractASTMatcherRule.h
@@ -14,7 +14,7 @@ class AbstractASTMatcherRule :
     public clang::ast_matchers::MatchFinder::MatchCallback
 {
 private:
-    clang::ast_matchers::MatchFinder _finder;
+    clang::ast_matchers::MatchFinder *_finder;

 protected:
     virtual void run(const clang::ast_matchers::MatchFinder::MatchResult &result)
@@ -25,27 +25,34 @@ protected:
     template<typename T>
     void addMatcher(const T &nodeMatch)
     {
-        _finder.addMatcher(nodeMatch, this);
+        _finder->addMatcher(nodeMatch, this);
     }

 public:
     virtual void setUp()
     {
+        _finder = new clang::ast_matchers::MatchFinder();
         setUpMatcher();
     }

     bool VisitDecl(clang::Decl *decl)
     {
-        _finder.match(*decl, *_carrier->getASTContext());
+        _finder->match(*decl, *_carrier->getASTContext());
         return true;
     }

     bool VisitStmt(clang::Stmt *stmt)
     {
-        _finder.match(*stmt, *_carrier->getASTContext());
+        _finder->match(*stmt, *_carrier->getASTContext());
         return true;
     }

+    virtual void tearDown()
+    {
+        delete _finder;
+        _finder = NULL;
+    }
+
 public:
     virtual ~AbstractASTMatcherRule() {}

Large projects cannot be analyzed due to high memory consumption

In oclint-driver/main.cpp the method driver.run() is called with all given source files. This creates a high memory load when having a large project. I implemented a workaround like this:

try
{
    for (size_t pathIndex = 0, pathEnd = optionsParser.getSourcePathList().size(); pathIndex != pathEnd; pathIndex++)
    {
        std::vector<std::string> sourcePathsCopy(1, optionsParser.getSourcePathList()[pathIndex]);
        driver.run(optionsParser.getCompilations(), sourcePathsCopy, analyzer);
    }
}

What would be the best solution for this?

Feature Envy and Data Clump rules

Hi @lqi,

I thought it would be better to move discussion of these rules to an dedicated issue.

For reference I've been working on these rules in https://github.com/joekain/oclint on DataClump and FeatureEnvy branches.

I agree that these rules will be very helpful for improving code quality analysis with oclint. I find I violate these rules more often than I am comfortable with and found that with ruby code the reek tool was very helpful in tracking down the problems. I first came across the oclint project when looking for tools that could help me do the same analysis with ObjC. And it has been a very pleasant experience working with oclint so far while developing these rules.

I've been testing the rules against one of my ObjC source bases and so far the rules seem to be working pretty well. It's been a few days since I've had a chance to work on these projects but, when I last tried running the dogfooding script with FeatureEnvy and DataClump they reported a number of violations in oclint. The biggest problem I could see is common C++/STL style tends to encourage some data clumping (especially with iterators) and feature envy of container classes. That is, storing, retrieving, and processing data in containers is envious of the container classes. In languages like ruby and ObjC it's possible (though not always clean) to add methods to library classes to fix these violations. I've been away from C++ for some time but I don't think that's a viable solution. Subclasses of container classes might be an option. But, I don't know that this is common practice or useful with STL.

Thoughts?

Tests and refactoring for oclint-xcodebuild

This helper program gradually can handle some complex cases, so the Python code behind it becomes complicated at the same time. It's necessary to have unit tests or some sorts of tests to ensure further changes won't change existing behaviors, or when the behaviors need to be changes, they still meet the expectation. In addition, after we have tests, we could refactor the code.

Configuration Persistence

Similar to the .xctool-args file of https://github.com/facebook/xctool, OCLint loads a configuration file (maybe oclint.rc or .oclint) from current directory and populates arguments from there. Arguments passing on the command line invocation would override the ones in the configuration file.

The format of configuration file is open for discussion, but needs to be lightweight. Formats leverage existing library dependencies are preferred. For example, YAML, since LLVM/Clang codebase has a YAML parser.

Build OCLint against out-of-tree llvm/clang

It would be nice if we could build oclint without having to build llvm/clang.

We should be able to build oclint just with the -dev packages of our favorites distributions.

Some variables are meant to be unused

Consider the following:

#include <boost/thread.hpp>

boost::mutex mut;

int main()
{
  boost::mutex::scoped_lock lock(mut);
  // Do work

  return 0;
}

When running this through oclint 0.6, it claims (correctly)

/home/kees-jan/src/tt/tt.cc:9:3: unused local variable P2

At this point, I do not want to disable the rule altogether (it might find some useful errors), but I also don't want to annotate each and every time I lock a mutex (or use a similar RAII style construct).

What is the recommended approach here?

Rule "collapsable if statements" too aggressive?

Hi!

Consider the following code:

if (OUTER_TEST_1) {
    if (INNER_TEST) {
        doSomething();
    } else {
        doSomethingDifferent();
    }
} else if (OUTER_TEST_2) {
   (...)
}

The oclint rule complains / suggests, that OUTER_TEST_1 and INNER_TEST should be combined into just one line.
Maybe I just don't see the optimization here, but I think, that the statements can't be combined since doSomethingDifferent shall only be reached, if INNER_TEST is false but OUTER_TEST_1 is true.

Is my code 'wrong' or should the rule 'look' a little bit further in the code?

MissingBreakInSwitchStatementRule false positive

Hi @lqi,

me again ;-)

oclint reports violations for the following code:

switch (type) {
    case WMSDocumentTypeCategory:
        fileName = WMSFileNameCategoryDocument;
        break;

    case WMSDocumentTypeItem:
        fileName = WMSFileNameItemDocument;
        break;

    case WMSDocumentTypePlace:
        fileName = WMSFileNamePlaceDocument;
        break;

    default:
        break;
}

The violations are reported for every switch that tests on variables, that are defined as enums.

I wrote a test case to examine the behavior:

TEST(MissingBreakInSwitchStatementRuleTest, CasesHaveBreaks2)
{
    testRuleOnCode(new MissingBreakInSwitchStatementRule(), "void aMethod(int a) { \n\
    typedef enum WMSDocumentType { \n\
    WMSDocumentTypeCategory  = 1 << 0, \n\
WMSDocumentTypeItem = 1 << 1, \n\
WMSDocumentTypePlace = 1 << 2 \n\
} WMSDocumentType; \n\
switch(a){\n\
case WMSDocumentTypeCategory:     \n\
\tbreak;    \n\
case WMSDocumentTypeItem:     \n\
\tbreak;    \n\
case WMSDocumentTypePlace:     \n\
\tbreak;    \n\
} }");
}

This test does not fail - so I assume, that oclint get's confused by the usage of enums somehow. They are declared in the .pch file. May that be the issue?

I assume, that the same behaviour applies to at least also the SwitchStatementsShouldHaveDefaultRule.

What do you think?

TeamCity Reporter

We have a group users who use TeamCity as continuous integration system. It will be good to improve the usability and experiences by having a reporter that is fully integrated with TeamCity.

oclint-xcodebuild Cocoapods issue

Hi,
After generating xcodbuild.log, I'm having issues running oclint-xcodebuild. It always says

cannot find original pch source file for somePathToApp/Build/Intermediates/PrecompiledHeaders/Pods-someLibrary-prefix-glnubredltgkkwcgovayawmxdebx/Pods-someLibrary-prefix.pch

I looked in to the directory that the script was trying to look into, there were only pch.d, pch.dia and pch.pth files, but no .pch file. The actual .pch was in the Pods/ folder under the in the project folder.
The weird thing about this is that some Cocoapods library can be analyzed correctly, like GRMustache, but most of the Cocoapods libraries generate this error, like OCMock, even though as far as I could tell, they all have the same file structure and same setup for Header Search Paths

A bit more information about the system:
I'm using Cocoapods and Cordova (Cordova library gets analyzed fine in the JSON file), so I generate my build log using something like this

xcodebuild -workspace app.xcworkspace/ -scheme app | tee xcodebuild.log 

After googling this issue, I didn't see any post mentioning similar problems, so I'm wondering if anyone else has run into this issue or know anything about it?

if (!strcmp()) flagged as "inverted logic" when there's an else block

This occurs in OClint version 0.6:

maxtothemax@maxtothemax-mint ~ $ oclint -version
LLVM (http://llvm.org/):
  LLVM version 3.2svn
  Optimized build.
  Built Dec 28 2012 (23:04:17).
  Default target: i386-pc-linux-gnu
  Host CPU: corei7

Here's a short but complete program that triggers the bug:

#include <stdio.h>
#include <string.h>

int main (int argc, char *argv[]) 
{
    if (!strcmp ("string", "string"))
        printf ("string equals string\n");
    else
        printf ("can't happen\n");
    return 0;
}

It produces the following output:

$ oclint oclint_strcmp_inverting.c --
Processing: /home/maxtothemax/code/wtf/oclint_strcmp_inverting.c.
OCLint Report

Summary: TotalFiles=1 FilesWithViolations=1 P1=0 P2=2 P3=1 

/home/maxtothemax/code/wtf/oclint_strcmp_inverting.c:6:9: inverted logic P3 
/home/maxtothemax/code/wtf/oclint_strcmp_inverting.c:4:11: unused method parameter P2 
/home/maxtothemax/code/wtf/oclint_strcmp_inverting.c:4:21: unused method parameter P2 

[OCLint (http://oclint.org) v0.6]

OCLint correctly doesn't complain if there's no "else" block. However, I'd argue that even if there is one, !strcmp() is idiomatic in C and shouldn't be considered a style issue.

False unused local variable warning with try/catch

Given the code:

bool g() {
    try {
        f();
    } catch (const std::exception &) {
        return false;
    }
    return true;
}

the catch (const std::exception &) generates a:

unused local variable P3

warning, even though the exception is not given a name. This is a common pattern for handling exceptions (as opposed to printing the exception as an error message).

Migrate to C++11

We would like to try to migrate the codebase to C++11 standard. We would leverage so many new features in the language level to make our code shorter and cleaner.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.