Discussion:
Formatting of "using" with structs
(too old to reply)
Andy
2018-10-19 10:50:57 UTC
Permalink
I've been updating some of my code from "typedef" to "using" style:

typedef int foo;

using foo = int;


When I try it with structs though the formatting gets all messed up in
Creator:

using FooInfo = struct

{

QString name;

QString code;

};


Do I have something set incorrectly or is it just a bug?

---
Andy Maloney // https://asmaloney.com
twitter ~ @asmaloney <https://twitter.com/asmaloney>
André Pönitz
2018-10-20 09:40:36 UTC
Permalink
Post by Andy
typedef int foo;
using foo = int;
When I try it with structs though the formatting gets all messed up in
using FooInfo = struct
{
QString name;
QString code;
};
Given that this is C++, not C, the canonical way to write this would be

struct FooInfo
{
QString name;
QString code;
};

i.e. neither typedef nor using.

Andre'
Andy
2018-10-20 12:15:05 UTC
Permalink
Thanks André.

Yes, I suppose that's true! Did I mention how old some of this code is? :-)

This might be a good case for clang-tidy (if it doesn't already exist).
Right now it recommends "using".

Even doing that I get something a little off - two indents instead of one:

struct FooInfo

{

QString name;

QString code;

};


I assume this has to do with the setting for public/private indentation,
though I would expect if those keywords aren't present it wouldn't add the
extra indent.

---
Andy Maloney // https://asmaloney.com
Post by André Pönitz
Post by Andy
typedef int foo;
using foo = int;
When I try it with structs though the formatting gets all messed up in
using FooInfo = struct
{
QString name;
QString code;
};
Given that this is C++, not C, the canonical way to write this would be
struct FooInfo
{
QString name;
QString code;
};
i.e. neither typedef nor using.
Andre'
Nikolai Kosjar
2018-10-22 07:06:43 UTC
Permalink
Post by Andy
Do I have something set incorrectly or is it just a bug?
Probably a bug. You could try the experimental ClangFormat plugin, but
note that it does not honor the Qt Creator settings.

Nikolai

Loading...