Menu ▾ ▴

#570 Wrong formatting of scientific notation in cpp

closed-fixed
None
2024-05-31
2024-05-13
Tomas M
No

Hello, thanks for this project!

The latest version (3.4.15) breaks cpp code when using scientific notation of numbers.

Original line of code:

  if ( vertex.isValid() && !InputUtils::equals( point, vertex.coordinates(), 1e-8 ) )

Formatted line of code:

  if ( vertex.isValid() && !InputUtils::equals( point, vertex.coordinates(), 1e - 8 ) )

Note the change for 1e - 8 this is invalid syntax and breaks compilation.

I also found another weird scenario. Function call with multiplication in arguments is formatted as pointer:

Original line of code:

f.setPixelSize( pixelSize * mDp );

Formatted line of code:

f.setPixelSize( pixelSize *mDp );

Version 3.4.15
Used parameters:

--preserve-date
--convert-tabs
--indent=spaces=2
--indent-classes
--indent-labels
--indent-namespaces
--indent-switches
--min-conditional-indent=-1
--suffix=none
--break-after-logical
--style=allman
--align-pointer=name
--align-reference=name
--keep-one-line-statements
--keep-one-line-blocks
--pad-paren-in
--pad-oper
--unpad-paren
--pad-header

Removing --pad-oper is a workaround for the bug with scientific notation.

Discussion

  • André Simon

    André Simon - 2024-05-14
    • status: open --> open-accepted
    • assigned_to: André Simon
     
  • André Simon

    André Simon - 2024-05-14

    Thx, it will be fixed soon

     
  • André Simon

    André Simon - 2024-05-21

    Fixed in 3.4.16. The second case (multiplication) cannot be resolved by astyle, a long term goal is to include LSP support to fix these issues.

     
  • w-peuker

    w-peuker - 2024-05-21

    Do you mean this LSP?

     
  • André Simon

    André Simon - 2024-05-21

    Yes, I have made a C++ client for my other pet project (highlight). astyle could make use of semantic token responses by clangd.

     
  • André Simon

    André Simon - 2024-05-31
    • status: open-accepted --> closed-fixed
     

Log in to post a comment.