Skip to content

const can be specified for a function argument more than once #729

@Daniel-Cortez

Description

@Daniel-Cortez

Issue description:

While working on an implementation of named-only function arguments (#719), I found an oversight in function declargs().

compiler/source/compiler/sc1.c

Lines 4278 to 4282 in 81b4a02

case tCONST:
if (ident!=iVARIABLE || numtags>0 || fpragma)
error(1,sc_tokens[tSYMBOL-tFIRST],sc_tokens[tCONST-tFIRST]);
fconst=TRUE;
break;

There's no check if const was already specified, although handlers for other specifiers (&, Tag:, ...) have this kind of check.
As a result, the user can specify const any number of times

Func(const const const const arg) {}

and the compiler would think this is okay, although it clearly isn't.

Minimal complete verifiable example (MCVE):

See above.

Workspace Information:

  • Compiler version: 3.10.10
  • Command line arguments provided (or sampctl version): Not relevant.
  • Operating System: Not relevant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions