Skip to content

warnings about common incorrect usage of exceptions #11723

@llvmbot

Description

@llvmbot
Bugzilla Link 11351
Version 2.9
OS Linux
Reporter LLVM Bugzilla Contributor
CC @DougGregor,@gribozavr

Extended Description

It would be great if clang showed warnings about common incorrect usage of exceptions and appropriate fix-it hint.

That is:

  1. "throw new"
  2. catch by value
  3. rethrow that change exception type
#include <stdexcept>


int main()
{
    try
    {
        throw new std::runtime_error("hello, kitty!"); // warning: "throw new", fix-it: remove "new"
    }
    catch (std::exception e) // warning: catch by value, fix-it: add "const&" or "&"
    {
        throw e; // warning: rethrow change a type, fix-it: remove "e"
    }
  
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions