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

False positive expression must have a constant value with __builtin_choose_expr in _Static_assert #10168

Closed
sammko opened this issue Nov 18, 2022 · 5 comments
Assignees
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Milestone

Comments

@sammko
Copy link

sammko commented Nov 18, 2022

Environment

  • OS and Version: Arch
  • VS Code Version: 1.74.0-insider 96db0b339360bc72d27d869d81a557540ad5f800
  • C/C++ Extension Version: v1.13.4 Pre-Release

Bug Summary and Steps to Reproduce

#define ELEMENTSOF(x)                                                    \
        (__builtin_choose_expr(                                          \
                !__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
                sizeof(x)/sizeof((x)[0]),                                \
                (void)0))

int main(void) {
    int array1[1] = {0};
    _Static_assert(ELEMENTSOF(array1) <= 20, "hi");
    return 0;
}

An error "expression must have a constant value" is reported. Changing compiler, c standard and intelli sense mode didn't help. The program compiles under both gcc and clang with -Wall -Wextra -pedantic. gcc is quiet, clang gives only a warning

xyz.c:9:20: warning: extension used [-Wlanguage-extension-token]
    _Static_assert(ELEMENTSOF(array1) <= 20, "hi");
                   ^
xyz.c:3:47: note: expanded from macro 'ELEMENTSOF'
                !__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
                                              ^
xyz.c:9:20: warning: extension used [-Wlanguage-extension-token]
xyz.c:3:58: note: expanded from macro 'ELEMENTSOF'
                !__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \

Related to #8294

@sean-mcmanus
Copy link
Collaborator

This is a duplicate of #9368

@sean-mcmanus sean-mcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Nov 18, 2022
@sammko
Copy link
Author

sammko commented Nov 18, 2022

Is it? Happens with

"compilerPath": "/usr/bin/gcc",
"intelliSenseMode": "linux-gcc-x64",

Also no function pointers involved?

@sean-mcmanus sean-mcmanus reopened this Nov 18, 2022
@sean-mcmanus sean-mcmanus self-assigned this Nov 18, 2022
@sean-mcmanus sean-mcmanus added this to the 1.14.0 milestone Nov 18, 2022
@sean-mcmanus sean-mcmanus added bug fixed Check the Milestone for the release in which the fix is or will be available. labels Nov 18, 2022
@sean-mcmanus sean-mcmanus removed their assignment Nov 18, 2022
@sean-mcmanus
Copy link
Collaborator

sean-mcmanus commented Nov 18, 2022

The fix should be available when we release 1.14.0 (pre-release) -- not sure when yet. The issue I thought this was a duplicate of was already fixed in 1.13.4.

@sammko
Copy link
Author

sammko commented Nov 18, 2022

Awesome, thanks 👍

@sean-mcmanus sean-mcmanus self-assigned this Dec 7, 2022
@sean-mcmanus
Copy link
Collaborator

The fix is available with 1.14.0 (pre-release): https://github.com/microsoft/vscode-cpptools/releases/tag/v1.14.0

@github-actions github-actions bot locked and limited conversation to collaborators Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service
Projects
None yet
Development

No branches or pull requests

2 participants