Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 358983

Summary: Incorrect source code formatting when using BOOST_FOREACH
Product: [Tools] CDT Reporter: Michael <michael.fomin>
Component: cdt-otherAssignee: Doug Schaefer <cdtdoug>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: marco.stornelli, Tones, yevshif
Version: 8.0   
Target Milestone: 9.8.0   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Michael CLA 2011-09-26 19:46:54 EDT
Build Identifier: 20110615-0604

The Eclipse source code formatter (Ctrl+Shift+F) incorrectly formats code that includes the boost library BOOST_FOREACH macro.

As shown:

void foo()
{
	vector<int> vec;
	BOOST_FOREACH(int i, vec)
			{
				
			}
}

We can see the first '{' after the macro has 2 additional tabs.

Reproducible: Always

Steps to Reproduce:
1. Create C++ project
2. Use BOOST_FOREACH in function
3. Auto format code (Ctrl+Shift+F)
Comment 1 Andreas CLA 2013-04-01 12:50:56 EDT
With CDT 8.1.2 the autoformatting results look different, but still not in the way it is supposed to be:

void foo()
{
  std::vector<int> vec;
  BOOST_FOREACH(int & i, vec){
  ++i;
}
}

Changing the active formatter profile does not seem to resolve the isssue.
Comment 2 Marco Stornelli CLA 2019-04-14 05:01:45 EDT
I used this code:

#include <string>
#include <iostream>
#include <vector>
#include <boost/foreach.hpp>

int main() {
	std::string hello("Hello, world!");

	std::vector<int> vec;
	BOOST_FOREACH( int i, vec ) {
		std::cout << i;
	}

	return 0;
}

I can't reproduce this problem with CDT 9.7