microsoft / microsoft/vscode-cpptools
Issue with __VA_OPT__() keyword not expanding properly in a variadic macro
Nessuno ha ancora preso questa issue.
- Lingua principale
- TypeScript
- Stelle
- 6.2k
- Fork
- 1.7k
- Merge medio
- 14h 46m
- PR unite (30g)
- 61
Descrizione
Bug type: Language Service
Describe the bug
- OS and Version: Linux Ubuntu 20.04
- VS Code Version: 1.60.2
- C/C++ Extension Version: v1.7.1
- Other extensions you installed (and if the issue persists after disabling them): Python, Pylance, PlatformIO, Shader language support for VS Code, Todo+, Jupyter (after disabling all, the problem still persists).
- If using SSH remote, specify OS of remote machine:
- A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).
I was trying to program a C++ variadic macro that would print an error message tostderrlike this:
#define __pError(message, ...) \
{\
fprintf(stderr, "\x1B[31mERROR: Error at file %s, line %d:\x1B[0m ",\
__FILE__, __LINE__);\
fprintf(stderr, message __VA_OPT__(,) __VA_ARGS__);\
fprintf(stderr, "\n");\
exit(-1);\
}
I then used the macro like this:
__pError("I am going to produce an error!");
Now, this should work, but instead I get an error message:
" expected a ')' "
When I compile my project using g++, I don't get errored out; it compiles just fine.
I think the problem is with the VA_OPT() keyword; maybe it isn't implemented?
Steps to reproduce
- Make a file, let's call it file.h
- Paste the macro definition code into said file.
- At the top, put
#pragma once,#include <stdio.h>and#include <stdlib.h>. - Make another file, let's call it main.cpp.
- Insert
#include <file.h>at the top - Update
includePathin VSCode cpp configuration files to include file.h. - Put in a main function:
int main()
{
__pError("Why am I recieving an error?");
return 0;
}
- See error
Expected behavior
There should be no error; no red squiggly lines.
Code sample and logs
- Code sample
file.h:
#pragma once
#define __pError(message, ...) \
{\
fprintf(stderr, "\x1B[31mERROR: Error at file %s, line %d:\x1B[0m ",\
__FILE__, __LINE__);\
fprintf(stderr, message __VA_OPT__(,) __VA_ARGS__);\
fprintf(stderr, "\n");\
exit(-1);\
}
main.cpp:
#include "file.h"
int main()
{
__pError("Why am I recieving an error?");
return 0;
}
- Configurations in
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/include"
],
"defines": ["GL_GLEXT_PROTOTYPES"],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
- Logs from running
C/C++: Log Diagnosticsfrom the VS Code command palette
-------- Diagnostics - 10/30/2021, 6:54:58 PM
Version: 1.7.1
Current Configuration:
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/include"
],
"defines": [
"GL_GLEXT_PROTOTYPES"
],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"compilerPathIsExplicit": true,
"cStandardIsExplicit": true,
"cppStandardIsExplicit": true,
"intelliSenseModeIsExplicit": true,
"compilerArgs": [],
"mergeConfigurations": false,
"browse": {
"path": [
"${workspaceFolder}/include",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true
}
}
Translation Unit Mappings:
[ /home/ben/c/game/src/test.cpp ]:
/home/ben/c/game/src/test.cpp
/home/ben/c/game/include/Utils.h
Translation Unit Configurations:
[ /home/ben/c/game/src/test.cpp ]:
Process ID: 40704
Memory Usage: 14 MB
Compiler Path: /usr/bin/gcc
Includes:
/home/ben/c/game/include
/usr/include/c++/9
/usr/include/x86_64-linux-gnu/c++/9
/usr/include/c++/9/backward
/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include
Defines:
GL_GLEXT_PROTOTYPES
Standard Version: c++14
IntelliSense Mode: linux-gcc-x64
Other Flags:
--g++
--gnu_version=90300
Total Memory Usage: 14 MB
------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 5969
- Logs from the language server logging
Screenshots
None should be needed, but some can be provided if necessary.
Additional context
If more context is needed, I can provide, but I don't think any more is necessary.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo la diagnostica della macro da file.h e main.cpp con il c_cpp_properties.json fornito, quindi confronta lo standard C++ configurato con il comportamento del compilatore. Traccia il modo in cui il servizio del linguaggio analizza VA_OPT in questa macro variadica. Il lavoro è completato quando l’esempio fornito viene accettato senza l’errore di parentesi di chiusura segnalato, preservando il comportamento diagnostico esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- cpp
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100