| Summary: | Parser reports error for BOOST_FOREACH | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Tools] CDT | Reporter: | Nathan Ridge <zeratul976> | ||||
| Component: | cdt-indexer | Assignee: | Markus Schorn <mschorn.eclipse> | ||||
| Status: | RESOLVED FIXED | QA Contact: | Markus Schorn <mschorn.eclipse> | ||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | bb3138, bernhard.merkle, cdtdoug, fa_kong, jamesblackburn+eclipse, kolsrud, mhilbig, rmelch, trivial+eclipsebugs, waste.manager, yevshif | ||||
| Version: | 8.0 | ||||||
| Target Milestone: | 8.1.0 | ||||||
| Hardware: | All | ||||||
| OS: | All | ||||||
| Whiteboard: | |||||||
| Bug Depends on: | 197989, 367753 | ||||||
| Bug Blocks: | |||||||
| Attachments: |
|
||||||
This is still an issue with indigo-rc2, is there any way to ignore errors? And I get it still with Indigo. It's pretty annoying to always see error flags, but I don't want to completely disable Codan. As long as you're on a project which can be compiled with std=c++0x the workaround is using the for-range-syntax, which is supported by recent clang and gcc versions, and now cdt :) Actually, your project doesn't even need to use C++0x to take advantage of CDT 8.0's support for range-based for loops. You can write a "foreach" macro that looks like this:
#ifdef ECLIPSE_PARSER
#define foreach(a, b) for(a : b)
#else
#define foreach(a, b) BOOST_FOREACH(a, b)
#endif
and then define the symbol ECLIPSE_PARSER in eclipse project settings, but not in your makefile. This way, the eclipse parser will see range-based for loops and give no errors, and the compiler will see BOOST_FOREACH, which it can compiler without C++0x support.
(In reply to comment #4) > Actually, your project doesn't even need to use C++0x to take advantage of CDT > 8.0's support for range-based for loops. You can write a "foreach" macro that > looks like this: > > #ifdef ECLIPSE_PARSER > #define foreach(a, b) for(a : b) > #else > #define foreach(a, b) BOOST_FOREACH(a, b) > #endif > > and then define the symbol ECLIPSE_PARSER in eclipse project settings, but not > in your makefile. This way, the eclipse parser will see range-based for loops > and give no errors, and the compiler will see BOOST_FOREACH, which it can > compiler without C++0x support. Where in project settings do you set ECLIPSE_PARSER? (In reply to comment #5) > (In reply to comment #4) > > Actually, your project doesn't even need to use C++0x to take advantage of CDT > > 8.0's support for range-based for loops. You can write a "foreach" macro that > > looks like this: > > > > #ifdef ECLIPSE_PARSER > > #define foreach(a, b) for(a : b) > > #else > > #define foreach(a, b) BOOST_FOREACH(a, b) > > #endif > > > > and then define the symbol ECLIPSE_PARSER in eclipse project settings, but not > > in your makefile. This way, the eclipse parser will see range-based for loops > > and give no errors, and the compiler will see BOOST_FOREACH, which it can > > compiler without C++0x support. > Where in project settings do you set ECLIPSE_PARSER? Project Properties -> C/C++ General -> Paths and Symbols -> Symbols tab. Be sure to add it under the "GNU C++" Language, not "GNU C" which is selected by default. This is assuming you're using a makefile project. I'm not sure how to do this with managed build projects as I never use them. (In reply to comment #6) You can also use the built-in macro __CDT_PARSER__, it is always set by our preprocessor. (In reply to comment #7) > (In reply to comment #6) > You can also use the built-in macro __CDT_PARSER__, it is always set by our > preprocessor. Ah, good to know! Then it can be done with both makefile and managed build projects. (In reply to comment #7) > (In reply to comment #6) > You can also use the built-in macro __CDT_PARSER__, it is always set by our > preprocessor. Thanks this is just what I wanted. Just want to know when this can be fixed since it was not an issue in Eclipse 3.5 or 3.6. And it is annoying if I don't want to change my code as the "foreach" macro-define. It has always been an issue, you just haven't seen the red underline in 3.5 or 3.6 because that feature (showing red underlines for problems) was only introduced in 3.7. I strongly suspect that, like many issues involving boost, the root cause is https://bugs.eclipse.org/bugs/show_bug.cgi?id=197989. (Try preprocessing a file that uses BOOST_FOREACH and replacing the code in the editor with the preprocessed version - surprise surprise, the error goes away). Perhaps, this might be helpful. Actually, my workaround is even simpler and does not require adding/changing header files: 1. Goto Project Properties → Paths and Symbols → Symbols tab 2. Add name: BOOST_FOREACH(a,b) with value: for(a:b) I did this for both languages GNU C and GNU C++. After re-parsing all sources using the BOOST_FOREACH macro are recognized correctly. (Eclipse version: Indigo Service Release 1) Tested with Boost 1.46.1. |
Created attachment 184923 [details] preprocessed source file The parser reports an error for the following code: #include <boost/foreach.hpp> int main() { int array[3] = {1, 2, 3}; BOOST_FOREACH(int& i, array) i++; return 0; } The error is: Multiple markers at this line - Invalid arguments Candidates are: boost::foreach_detail_::type2type<#0,mpl_::bool_<1>> * encode_type(const #0 &, mpl_::bool_<1> *) boost::foreach_detail_::type2type<#0,mpl_::bool_<0>> * encode_type(#0 &, mpl_::bool_<0> *) - Invalid arguments Candidates are: ? * or_(#0 *, #1 *, #2 *) ? * or_(#0 *, #1 *) - Invalid arguments Candidates are: ? * and_(#0 *, #1 *, #2 *) ? * and_(#0 *, #1 *) - Invalid arguments Candidates are: boost::mpl::not_<#0> * not_(#0 *) - Invalid arguments Candidates are: boost::foreach_detail_::auto_any<#0> contain(const #0 &, mpl_::bool_<1> *) boost::foreach_detail_::auto_any<#0 *> contain(#0 &, mpl_::bool_<0> *) - Invalid arguments Candidates are: boost::foreach_detail_::foreach_reference<#0,#1>::type deref(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0,#1> *) - Invalid arguments Candidates are: void next(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0,#1> *) - Invalid arguments Candidates are: bool done(const boost::foreach_detail_::auto_any_base &, const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0,#1> *) bool done(const boost::foreach_detail_::auto_any_base &, const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0 *,#1> *) - Invalid arguments Candidates are: boost::foreach_detail_::auto_any<int> end(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0 *,#1> *, mpl_::bool_<1> *) boost::foreach_detail_::auto_any<boost::foreach_detail_::foreach_iterator<#0,#1>::type> end(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0,#1> *, mpl_::bool_<0> *) boost::foreach_detail_::auto_any<boost::foreach_detail_::foreach_iterator<#0,#1>::type> end(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0,#1> *, mpl_::bool_<1> *) - Invalid arguments Candidates are: boost::foreach_detail_::auto_any<#0 *> begin(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0 *,#1> *, mpl_::bool_<1> *) boost::foreach_detail_::auto_any<boost::foreach_detail_::foreach_iterator<#0,#1>::type> begin(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0,#1> *, mpl_::bool_<0> *) boost::foreach_detail_::auto_any<boost::foreach_detail_::foreach_iterator<#0,#1>::type> begin(const boost::foreach_detail_::auto_any_base &, boost::foreach_detail_::type2type<#0,#1> *, mpl_::bool_<1> *) This error occurs every time BOOST_FOREACH is used, I just gave one example. I have attached the preprocessed source file.