Community
Participate
Working Groups
There are two possible ways to place the const qualifier according to the C++ specification: const int i { 42 }; // #1 int const y { 43 }; // #2 However, CDT supports only #1 at the moment. It should be made possible for the user to choose which placement he/she prefers. Therefore, the preferences and save actions in CDT should be extended to support the choice of the preferred const placement.
(In reply to Mario Meili from comment #0) > There are two possible ways to place the const qualifier according to the > C++ specification: > > const int i { 42 }; // #1 > int const y { 43 }; // #2 > > However, CDT supports only #1 at the moment. What do you mean by this? If you're referring to the formatter, it doesn't re-order tokens, it just adjusts the amount and kind of whitespace between them. Whichever order you wrote the "const" and the "int" in, will be preserved.
New Gerrit change created: https://git.eclipse.org/r/70930
(In reply to Nathan Ridge from comment #1) > (In reply to Mario Meili from comment #0) > > There are two possible ways to place the const qualifier according to the > > C++ specification: > > > > const int i { 42 }; // #1 > > int const y { 43 }; // #2 > > > > However, CDT supports only #1 at the moment. > > What do you mean by this? > > If you're referring to the formatter, it doesn't re-order tokens, it just > adjusts the amount and kind of whitespace between them. Whichever order you > wrote the "const" and the "int" in, will be preserved. Hi Nathan The patch is supposed to let the user choose how the formatter should behave. The save action realigns all const qualifiers according to the users choice.
Thanks for writing a patch! I understand now: the patch doesn't change the formatter, but it adds a Code Style preference that affects how the save action behaves.
The patch should also add an entry to org.eclipse.cdt.ui/plugin.xml to include the setting when exporting preferences, something like this: diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 9300339..ababbc0 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -4906,6 +4906,7 @@ <key name="forwardDeclare." match="prefix"/> <key name="function_output_parameters_before_input"/> <key name="function_pass_output_parameters_by_pointer"/> + <key name="place_const_right_of_type"/> <key name="nameStyle." match="prefix"/> <key name="organizeIncludes." match="prefix"/> </entry>
(In reply to Mirko Stocker from comment #5) > The patch should also add an entry to org.eclipse.cdt.ui/plugin.xml to > include the setting when exporting preferences, something like this: > > diff --git a/core/org.eclipse.cdt.ui/plugin.xml > b/core/org.eclipse.cdt.ui/plugin.xml > index 9300339..ababbc0 100644 > --- a/core/org.eclipse.cdt.ui/plugin.xml > +++ b/core/org.eclipse.cdt.ui/plugin.xml > @@ -4906,6 +4906,7 @@ > <key name="forwardDeclare." match="prefix"/> > <key name="function_output_parameters_before_input"/> > <key name="function_pass_output_parameters_by_pointer"/> > + <key name="place_const_right_of_type"/> > <key name="nameStyle." match="prefix"/> > <key name="organizeIncludes." match="prefix"/> > </entry> Thank you Mirko for pointing this out. I applied this change and also rebased my patch with the current master branch.
New Gerrit change created: https://git.eclipse.org/r/94893
Gerrit change https://git.eclipse.org/r/70930 was merged to [master]. Commit: http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=ca1ab7f52dc9174ca42660d5acbe3b634de7ee9e