yodamaster / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
0 stars 0 forks source link

forward declares added when used with catch #172

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
iwyu will attempt to replace an include with a forward declare when used with 
try/catch. But you cant' catch an incomplete type

Example
exception.hpp has a class declaration, defined in exception.cpp:
class Compiler::SourceException : public std::exception {...stuff...}

Another source:
#include "exception.hpp"
try { something that throws an exception }
catch ( const Compiler::SourceException&) { ..stuff...}

iwyu will replace
#include "exception.hpp"
with
namespace Compiler { class SourceException; }

which will fail to compile:
error: cannot catch reference to incomplete type 'const 
Compiler::SourceException'
        catch (const Compiler::SourceException&)

What version of the product are you using? On what operating system?
clang,iwyu 3.5 linux

Original issue reported on code.google.com by showard...@gmail.com on 5 Feb 2015 at 4:33

GoogleCodeExporter commented 9 years ago
I fixed this yesterday :-)

See r598. Could you try this with IWYU trunk and let me know if it still 
persists? The namespace qualification could actually still confuse this.

Original comment by kim.gras...@gmail.com on 5 Feb 2015 at 4:44

GoogleCodeExporter commented 9 years ago
I'm getting compiler errors when building from trunk (tags/clang_3.5 builds 
fine), building with clang or gcc fails:

/usr/bin/c++   -DIWYU_SVN_REVISION=\"598\" -D__STDC_CONSTANT_MACROS 
-D__STDC_LIMIT_MACROS -fno-rtti -std=c++11 -I/usr/lib/llvm-3.5/include    -o 
CMakeFiles/include-what-you-use.dir/iwyu.cc.o -c 
/home/showard/openmw/include-what-you-use/iwyu.cc
/home/showard/openmw/include-what-you-use/iwyu.cc:3786:40: error: conflicting 
return type specified for ‘virtual std::unique_ptr<clang::ASTConsumer> 
include_what_you_use::IwyuAction::CreateASTConsumer(clang::CompilerInstance&, 
llvm::StringRef)’
   virtual std::unique_ptr<ASTConsumer> CreateASTConsumer(
                                        ^
In file included from /home/showard/openmw/include-what-you-use/iwyu.cc:133:0:
/usr/lib/llvm-3.5/include/clang/Frontend/FrontendAction.h:64:24: error:   
overriding ‘virtual clang::ASTConsumer* 
clang::FrontendAction::CreateASTConsumer(clang::CompilerInstance&, 
llvm::StringRef)’
   virtual ASTConsumer *CreateASTConsumer(CompilerInstance &CI,
                        ^
/home/showard/openmw/include-what-you-use/iwyu.cc: In member function 
‘virtual std::unique_ptr<clang::ASTConsumer> 
include_what_you_use::IwyuAction::CreateASTConsumer(clang::CompilerInstance&, 
llvm::StringRef)’:
/home/showard/openmw/include-what-you-use/iwyu.cc:3796:60: error: no matching 
function for call to 
‘clang::Preprocessor::addPPCallbacks(std::unique_ptr<clang::PPCallbacks>)’
         std::unique_ptr<PPCallbacks>(preprocessor_consumer));
                                                            ^
/home/showard/openmw/include-what-you-use/iwyu.cc:3796:60: note: candidate is:
In file included from 
/home/showard/openmw/include-what-you-use/iwyu_preprocessor.h:73:0,
                 from /home/showard/openmw/include-what-you-use/iwyu.cc:113:
/usr/lib/llvm-3.5/include/clang/Lex/Preprocessor.h:569:8: note: void 
clang::Preprocessor::addPPCallbacks(clang::PPCallbacks*)
   void addPPCallbacks(PPCallbacks *C) {
        ^
/usr/lib/llvm-3.5/include/clang/Lex/Preprocessor.h:569:8: note:   no known 
conversion for argument 1 from ‘std::unique_ptr<clang::PPCallbacks>’ to 
‘clang::PPCallbacks*’

Original comment by showard...@gmail.com on 5 Feb 2015 at 6:46

GoogleCodeExporter commented 9 years ago
We try to keep IWYU trunk compatible with Clang/LLVM trunk; the tags are only 
compatible with their respective releases of the upstream project.

I'll give your example a try against my trunk build so you don't have to put a 
lot of time into building IWYU/Clang/LLVM trunk if it doesn't work.

Original comment by kim.gras...@gmail.com on 5 Feb 2015 at 7:13

GoogleCodeExporter commented 9 years ago
I just added a test with an elaborated exception type in r599 and it worked out 
of the box, so I'd like to close this.

Now rebuilding my BSD working copy with Clang/LLVM HEAD to make sure we're 
up-to-date there too.

See here for instructions on how to build in-tree against Clang/LLVM HEAD:
https://code.google.com/p/include-what-you-use/wiki/InstructionsForUsers#Buildin
g_in-tree

Original comment by kim.gras...@gmail.com on 5 Feb 2015 at 7:28

GoogleCodeExporter commented 9 years ago
it works! thanks

Original comment by showard...@gmail.com on 5 Feb 2015 at 8:38

GoogleCodeExporter commented 9 years ago
it works! thanks

Original comment by showard...@gmail.com on 5 Feb 2015 at 8:39

GoogleCodeExporter commented 9 years ago
Great! Marking as duplicate of issue 171.

Original comment by kim.gras...@gmail.com on 6 Feb 2015 at 4:42