Issue 172 in include-what-you-use: forward declares added when used with catch

50 views
Skip to first unread message

include-wh...@googlecode.com

unread,
Feb 5, 2015, 11:34:09 AM2/5/15
to include-wh...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 172 by showard...@gmail.com: forward declares added when used
with catch
https://code.google.com/p/include-what-you-use/issues/detail?id=172

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

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings

include-wh...@googlecode.com

unread,
Feb 5, 2015, 11:45:11 AM2/5/15
to include-wh...@googlegroups.com

Comment #1 on issue 172 by kim.gras...@gmail.com: forward declares added
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.

include-wh...@googlecode.com

unread,
Feb 5, 2015, 1:46:36 PM2/5/15
to include-wh...@googlegroups.com

Comment #2 on issue 172 by showard...@gmail.com: forward declares added
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*’

include-wh...@googlecode.com

unread,
Feb 5, 2015, 2:13:32 PM2/5/15
to include-wh...@googlegroups.com

Comment #3 on issue 172 by kim.gras...@gmail.com: forward declares added
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.

include-wh...@googlecode.com

unread,
Feb 5, 2015, 2:29:16 PM2/5/15
to include-wh...@googlegroups.com

Comment #4 on issue 172 by kim.gras...@gmail.com: forward declares added
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#Building_in-tree

include-wh...@googlecode.com

unread,
Feb 5, 2015, 3:39:07 PM2/5/15
to include-wh...@googlegroups.com

Comment #5 on issue 172 by showard...@gmail.com: forward declares added
it works! thanks

include-wh...@googlecode.com

unread,
Feb 5, 2015, 3:40:08 PM2/5/15
to include-wh...@googlegroups.com

Comment #6 on issue 172 by showard...@gmail.com: forward declares added

include-wh...@googlecode.com

unread,
Feb 5, 2015, 11:42:12 PM2/5/15
to include-wh...@googlegroups.com
Updates:
Status: Duplicate

Comment #7 on issue 172 by kim.gras...@gmail.com: forward declares added
Great! Marking as duplicate of issue 171.
Reply all
Reply to author
Forward
0 new messages