Skip to content

[SUGGESTION] Allow const declarations to not require a wildcard _ #1120

@DyXel

Description

@DyXel

This change would make the following compile:

main: () = {
    my_int1: const   = 1; // Errors today.
    my_int2: const _ = 2; // Above would be equivalent to this.
}

outputs:

test.cpp2...
test.cpp2(2,22): error: '*'/'const' type qualifiers must be followed by a type name or '_' wildcard (at '=')

Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code? No.

Will your feature suggestion automate or eliminate X% of current C++ guidance literature? No. Maybe for cpp2 itself? I am just surprised that just const doesn't work even though _ is already the default.

Describe alternatives you've considered.
I added the _ as the compiler demanded, but guess what, I added it to the wrong side since I am so used to east-const 😅 The reason I added the const to begin with was because I wanted to quickly check if the function was mutating my variable down below quickly, but got this error instead, this causes friction when iterating code.

What about pointers (*)?
I am not sure. There's a clang-tidy fix-it that automatically adds the pointer to auto for readability: readability-qualified-auto which seems to indicate some developers like this style?

Personally I don't think that my_pointer: * = something& would be more readable, it doesn't seem that way to me, it just seems redundant. I also don't know if allowing that would help meta/generation (like having trailing commas do).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions