Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template move constructor parameter is seen as boolean operator #4254

Open
pemessier opened this issue Feb 29, 2024 · 3 comments
Open

Template move constructor parameter is seen as boolean operator #4254

pemessier opened this issue Feb 29, 2024 · 3 comments

Comments

@pemessier
Copy link

Using Uncrustify-0.78.1_f, with with this configuration:

  • sp_bool = add

Consider this working example, where Uncrustify produces the same output as this input:

template<> CExpected<TType>::CExpected(TType&& attached_);

Debug output:

# Uncrustify-0.78.1_f
sp_bool                         = add
# option(s) with 'not default' value: 1
#
# -=====-
# number of loops               = 0
# -=====-
# language                      = C-Header
# -=====-
# Line                Tag         Parent_type  Type of the parent         Columns Br/Lvl/pp     Nl  Text
#   1>           TEMPLATE|               NONE|     PARENT_NOT_SET[  1/  1/  9/  0][0/0/0][0-0] template
#   1>         ANGLE_OPEN|           TEMPLATE|     PARENT_NOT_SET[  9/  9/ 10/  0][0/0/0][0-0]         <
#   1>        ANGLE_CLOSE|           TEMPLATE|     PARENT_NOT_SET[ 10/ 10/ 11/  0][0/0/0][0-0]          >
#   1>               WORD|               NONE|     PARENT_NOT_SET[ 12/ 12/ 21/  1][0/0/0][0-0]            CExpected
#   1>         ANGLE_OPEN|           TEMPLATE|     PARENT_NOT_SET[ 21/ 21/ 22/  0][0/0/0][0-0]                     <
#   1>               TYPE|               NONE|     PARENT_NOT_SET[ 22/ 22/ 27/  0][0/1/0][0-0]                      TType
#   1>        ANGLE_CLOSE|           TEMPLATE|     PARENT_NOT_SET[ 27/ 27/ 28/  0][0/0/0][0-0]                           >
#   1>          DC_MEMBER|               NONE|     PARENT_NOT_SET[ 28/ 28/ 30/  0][0/0/0][0-0]                            ::
#   1>   FUNC_CLASS_PROTO|               NONE|     PARENT_NOT_SET[ 30/ 30/ 39/  0][0/0/0][0-0]                              CExpected
#   1>        FPAREN_OPEN|   FUNC_CLASS_PROTO|     PARENT_NOT_SET[ 39/ 39/ 40/  0][0/0/0][0-0]                                       (
#   1>               TYPE|               NONE|     PARENT_NOT_SET[ 40/ 40/ 45/  0][0/1/0][0-0]                                        TType
#   1>              BYREF|               NONE|     PARENT_NOT_SET[ 45/ 45/ 47/  0][0/1/0][0-0]                                             &&
#   1>               WORD|               NONE|     PARENT_NOT_SET[ 48/ 48/ 57/  1][0/1/0][0-0]                                                attached_
#   1>       FPAREN_CLOSE|   FUNC_CLASS_PROTO|     PARENT_NOT_SET[ 57/ 57/ 58/  0][0/0/0][0-0]                                                         )
#   1>          SEMICOLON|   FUNC_CLASS_PROTO|     PARENT_NOT_SET[ 58/ 58/ 59/  0][0/0/0][0-0]                                                          ;
#   1>            NEWLINE|               NONE|     PARENT_NOT_SET[ 59/ 59/  1/  0][0/0/0][1-0]
# -=====-

Now if we change the class name using an alias:

using TClass = CExpected<TType>;
template<> TClass::CExpected(TType&& attached_);

Uncrustify adds a space between TType and && because && is seen as BOOL istead of BYREF:

using TClass = CExpected<TType>;
template<> TClass::CExpected(TType && attached_);

Debug output:

# Uncrustify-0.78.1_f
sp_bool                         = add
# option(s) with 'not default' value: 1
#
# -=====-
# number of loops               = 0
# -=====-
# language                      = C-Header
# -=====-
# Line                Tag         Parent_type  Type of the parent         Columns Br/Lvl/pp     Nl  Text
#   1>              USING|        USING_ALIAS|     PARENT_NOT_SET[  1/  1/  6/  0][0/0/0][0-0] using
#   1>               WORD|        USING_ALIAS|     PARENT_NOT_SET[  7/  7/ 13/  1][0/0/0][0-0]       TClass
#   1>             ASSIGN|        USING_ALIAS|     PARENT_NOT_SET[ 14/ 14/ 15/  1][0/0/0][0-0]              =
#   1>               WORD|        USING_ALIAS|     PARENT_NOT_SET[ 16/ 16/ 25/  1][0/0/0][0-0]                CExpected
#   1>         ANGLE_OPEN|           TEMPLATE|     PARENT_NOT_SET[ 25/ 25/ 26/  0][0/0/0][0-0]                         <
#   1>               TYPE|        USING_ALIAS|     PARENT_NOT_SET[ 26/ 26/ 31/  0][0/1/0][0-0]                          TType
#   1>        ANGLE_CLOSE|           TEMPLATE|     PARENT_NOT_SET[ 31/ 31/ 32/  0][0/0/0][0-0]                               >
#   1>          SEMICOLON|        USING_ALIAS|     PARENT_NOT_SET[ 32/ 32/ 33/  0][0/0/0][0-0]                                ;
#   1>            NEWLINE|               NONE|     PARENT_NOT_SET[ 33/ 33/  1/  0][0/0/0][1-0]
#   2>           TEMPLATE|               NONE|     PARENT_NOT_SET[  1/  1/  9/  0][0/0/0][0-0] template
#   2>         ANGLE_OPEN|           TEMPLATE|     PARENT_NOT_SET[  9/  9/ 10/  0][0/0/0][0-0]         <
#   2>        ANGLE_CLOSE|           TEMPLATE|     PARENT_NOT_SET[ 10/ 10/ 11/  0][0/0/0][0-0]          >
#   2>               TYPE|               NONE|     PARENT_NOT_SET[ 12/ 12/ 18/  1][0/0/0][0-0]            TClass
#   2>          DC_MEMBER|               NONE|     PARENT_NOT_SET[ 18/ 18/ 20/  0][0/0/0][0-0]                  ::
#   2>          FUNC_CALL|               NONE|     PARENT_NOT_SET[ 20/ 20/ 29/  0][0/0/0][0-0]                    CExpected
#   2>        FPAREN_OPEN|          FUNC_CALL|     PARENT_NOT_SET[ 29/ 29/ 30/  0][0/0/0][0-0]                             (
#   2>               WORD|               NONE|     PARENT_NOT_SET[ 30/ 30/ 35/  0][0/1/0][0-0]                              TType
#   2>               BOOL|               NONE|     PARENT_NOT_SET[ 36/ 35/ 37/  0][0/1/0][0-0]                                    &&
#   2>               WORD|               NONE|     PARENT_NOT_SET[ 39/ 38/ 47/  1][0/1/0][0-0]                                       attached_
#   2>       FPAREN_CLOSE|          FUNC_CALL|     PARENT_NOT_SET[ 48/ 47/ 48/  0][0/0/0][0-0]                                                )
#   2>          SEMICOLON|               NONE|     PARENT_NOT_SET[ 49/ 48/ 49/  0][0/0/0][0-0]                                                 ;
#   2>            NEWLINE|               NONE|     PARENT_NOT_SET[ 50/ 49/  1/  0][0/0/0][1-0]
# -=====-

However, if we use int instead of TType the result is correct:

using TClass = CExpected<TType>;
template<> TClass::CExpected(int&& attached_);

Debug output:

# Uncrustify-0.78.1_f
sp_bool                         = add
# option(s) with 'not default' value: 1
#
# -=====-
# number of loops               = 0
# -=====-
# language                      = C-Header
# -=====-
# Line                Tag         Parent_type  Type of the parent         Columns Br/Lvl/pp     Nl  Text
#   1>              USING|        USING_ALIAS|     PARENT_NOT_SET[  1/  1/  6/  0][0/0/0][0-0] using
#   1>               WORD|        USING_ALIAS|     PARENT_NOT_SET[  7/  7/ 13/  1][0/0/0][0-0]       TClass
#   1>             ASSIGN|        USING_ALIAS|     PARENT_NOT_SET[ 14/ 14/ 15/  1][0/0/0][0-0]              =
#   1>               WORD|        USING_ALIAS|     PARENT_NOT_SET[ 16/ 16/ 25/  1][0/0/0][0-0]                CExpected
#   1>         ANGLE_OPEN|           TEMPLATE|     PARENT_NOT_SET[ 25/ 25/ 26/  0][0/0/0][0-0]                         <
#   1>               TYPE|        USING_ALIAS|     PARENT_NOT_SET[ 26/ 26/ 31/  0][0/1/0][0-0]                          TType
#   1>        ANGLE_CLOSE|           TEMPLATE|     PARENT_NOT_SET[ 31/ 31/ 32/  0][0/0/0][0-0]                               >
#   1>          SEMICOLON|        USING_ALIAS|     PARENT_NOT_SET[ 32/ 32/ 33/  0][0/0/0][0-0]                                ;
#   1>            NEWLINE|               NONE|     PARENT_NOT_SET[ 33/ 33/  1/  0][0/0/0][1-0]
#   2>           TEMPLATE|               NONE|     PARENT_NOT_SET[  1/  1/  9/  0][0/0/0][0-0] template
#   2>         ANGLE_OPEN|           TEMPLATE|     PARENT_NOT_SET[  9/  9/ 10/  0][0/0/0][0-0]         <
#   2>        ANGLE_CLOSE|           TEMPLATE|     PARENT_NOT_SET[ 10/ 10/ 11/  0][0/0/0][0-0]          >
#   2>               TYPE|               NONE|     PARENT_NOT_SET[ 12/ 12/ 18/  1][0/0/0][0-0]            TClass
#   2>          DC_MEMBER|               NONE|     PARENT_NOT_SET[ 18/ 18/ 20/  0][0/0/0][0-0]                  ::
#   2>          FUNC_CALL|               NONE|     PARENT_NOT_SET[ 20/ 20/ 29/  0][0/0/0][0-0]                    CExpected
#   2>        FPAREN_OPEN|          FUNC_CALL|     PARENT_NOT_SET[ 29/ 29/ 30/  0][0/0/0][0-0]                             (
#   2>               TYPE|               NONE|     PARENT_NOT_SET[ 30/ 30/ 33/  0][0/1/0][0-0]                              int
#   2>              BYREF|               NONE|     PARENT_NOT_SET[ 33/ 33/ 35/  0][0/1/0][0-0]                                 &&
#   2>               WORD|               NONE|     PARENT_NOT_SET[ 36/ 36/ 45/  1][0/1/0][0-0]                                    attached_
#   2>       FPAREN_CLOSE|          FUNC_CALL|     PARENT_NOT_SET[ 45/ 45/ 46/  0][0/0/0][0-0]                                             )
#   2>          SEMICOLON|               NONE|     PARENT_NOT_SET[ 46/ 46/ 47/  0][0/0/0][0-0]                                              ;
#   2>            NEWLINE|               NONE|     PARENT_NOT_SET[ 47/ 47/  1/  0][0/0/0][1-0]
# -=====-
@guy-maurel
Copy link
Contributor

The current git version works pretty fine under Linux Mint.
https://github.com/uncrustify/uncrustify
Please test it and report!
ca marche bien avec linux, quel systeme as-tu?

@pemessier
Copy link
Author

I build the latest sources on Windows.

uncrustify-4254.zip

C:\Users\pemessier\Desktop\uncrustify-master\out\build\x64-Debug>uncrustify.exe -c config.txt code.cpp
Output suffix: .uncrustify
do_source_file: Parsing: code.cpp as language CPP

I included the generated file (code.cpp.uncrustify). I expect no difference between this file and code.cpp.

@guy-maurel
Copy link
Contributor

Sorry, I correct:
uncrustify doesn't recognize TType as a type.
You may say it:

sp_bool = add
set type TType 

to get want you wanted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants