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

__builtin_choose_expr is not evaluated in constant contexts #8294

Closed
medhefgo opened this issue Oct 18, 2021 · 4 comments
Closed

__builtin_choose_expr is not evaluated in constant contexts #8294

medhefgo opened this issue Oct 18, 2021 · 4 comments
Labels
bug fixed Check the Milestone for the release in which the fix is or will be available. Language Service Visual Studio Inherited from Visual Studio
Milestone

Comments

@medhefgo
Copy link

medhefgo commented Oct 18, 2021

Bug type: Language Service

Describe the bug

  • OS and Version: Arch Linux
  • VS Code Version: 1.61.1
  • C/C++ Extension Version: 1.7.0

The following code sample produces bogus warnings that neither gcc or clang produce when compiling. The macro is from systemd and is designed to give a compiler error if the expression cannot be evaluated at compile time.

#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] = {};
    int array2[__builtin_choose_expr(1, 1, (void)0)] = {};
    int array3[ELEMENTSOF(array1)] = {};
    return 0;
}

variable may not be initialized and incomplete type is not allowed warnings for both array2 and array3 despite the fact that the expression is/must be evaluated at compile time (which is kind of the whole point of __builtin_choose_expr).

@Colengms
Copy link
Contributor

Hi @medhefgo . Thanks for reporting this. I'm able to also reproduce the issue in VS, so I've opened an internal issue against VS.

@Colengms Colengms added Language Service Visual Studio Inherited from Visual Studio labels Oct 19, 2021
@Colengms Colengms added this to the Tracking milestone Oct 19, 2021
@sean-mcmanus sean-mcmanus added the fixed Check the Milestone for the release in which the fix is or will be available. label May 18, 2022
@sean-mcmanus sean-mcmanus modified the milestones: Tracking, 1.10.3 May 18, 2022
@sean-mcmanus
Copy link
Contributor

This is fixed with 1.10.3 (pre-release).

@sean-mcmanus
Copy link
Contributor

sean-mcmanus commented Jun 1, 2022

But it's only fixed for gcc mode and not clang...so we either need to keep this open or create a new issue to track that case.

@sean-mcmanus
Copy link
Contributor

The remaining bug with clang mode is being tracked by #9368

@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2022
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 Visual Studio Inherited from Visual Studio
Projects
None yet
Development

No branches or pull requests

3 participants