microsoft / microsoft/vscode-cpptools
Issue with __VA_OPT__() keyword not expanding properly in a variadic macro
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- TypeScript
- Sterne
- 6.2k
- Forks
- 1.7k
- Ø Merge
- 14 Std. 46 Min.
- Gemergte PRs (30 T.)
- 61
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Makrodiagnose aus file.h und main.cpp mit der bereitgestellten c_cpp_properties.json zu reproduzieren, und vergleiche anschließend den konfigurierten C++-Standard mit dem Compilerverhalten. Verfolge, wie der Sprachdienst VA_OPT in diesem variadischen Makro analysiert. Als erledigt gilt die Aufgabe, wenn das bereitgestellte Beispiel ohne den gemeldeten Fehler zur schließenden Klammer akzeptiert wird und das bestehende Diagnoseverhalten erhalten bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- cpp
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 52/100