Bugzilla will undergo maintenance 2024-03-29 18h00 CET. Bugzilla will be placed in read-only mode at that time.

Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 491957 - Preferences and save actions extension for choosing the alignment of the const qualifer
Summary: Preferences and save actions extension for choosing the alignment of the cons...
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-editor (show other bugs)
Version: Next   Edit
Hardware: PC Mac OS X
: P3 normal (vote)
Target Milestone: 9.3.0   Edit
Assignee: Thomas Corbat CLA
QA Contact: Anton Leherbauer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-04-19 03:10 EDT by Mario Meili CLA
Modified: 2017-05-15 04:13 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mario Meili CLA 2016-04-19 03:10:53 EDT
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.
Comment 1 Nathan Ridge CLA 2016-04-19 03:26:07 EDT
(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.
Comment 2 Eclipse Genie CLA 2016-04-19 03:28:41 EDT
New Gerrit change created: https://git.eclipse.org/r/70930
Comment 3 Mario Meili CLA 2016-04-19 03:32:14 EDT
(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.
Comment 4 Nathan Ridge CLA 2016-04-20 03:06:57 EDT
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.
Comment 5 Mirko Stocker CLA 2016-07-06 05:29:52 EDT
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>
Comment 6 Mario Meili CLA 2016-07-15 07:53:22 EDT
(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.
Comment 7 Eclipse Genie CLA 2017-04-12 04:30:56 EDT
New Gerrit change created: https://git.eclipse.org/r/94893