SkullHeadI
SkullHeadI

Reputation: 39

this declaration has no storage class or type specifier - compiler not detecting consteval

I have a question about why I'm getting the two problems, this declaration has no storage class or type specifier, and expected a ';' ln 3 col 11, of the code: Main.cpp:

#include <iostream>

consteval int get_value(){
    return 3;
}

int main(){
    constexpr int value = get_value();
    std::cout << "value : " << value << std::endl;
    return 0;
}

For some reason with this code my compiler doesn't detect consteval as a valid int.

Tasks.Json file


{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "Build with MSVC",
            "command": "cl.exe",
            "args": [
                "/Zi",
                "/std:c++20",
                "/EHsc",
                "/Fe:",
                "${fileDirname}\\rooster.exe",
                "${workspaceFolder}\\*.cpp"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$msCompile"
            ],
            "group": "build",
            "detail": "compiler: cl.exe"
        }
    ]
}

c_cppp_properties.json


{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.19041.0",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}

I'm using cl.exe to compile and run task on visual studio code. my compiler cl.exe version is Microsoft (R) C/C++ Optimizing Compiler Version 19.41.34120 for x86. Any solutions are greatly appreciated, thanks!

I've tried changing cpp standard from c++latest to c++20, because I thought that consteval wasn't being detected because c++20 wasn't a confirmed standard.

 *  Executing task: Build with MSVC 

Starting build...
cmd /c chcp 65001>nul && cl.exe /Zi /std:c++20 /EHsc /Fe: C:\Scripts\c++Scripts\The-C-20-Masterclass-Source-Code-main\The-C-20-Masterclass-Source-Code-main\02.EnvironmentSetup\1.Windows\4.V_s_CodeMsvcConfiguration\rooster.exe C:\Scripts\c++Scripts\The-C-20-Masterclass-Source-Code-main\The-C-20-Masterclass-Source-Code-main\*.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.41.34120 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

*.cpp
c1xx: fatal error C1083: Cannot open source file: 'C:\Scripts\c++Scripts\The-C-20-Masterclass-Source-Code-main\The-C-20-Masterclass-Source-Code-main\*.cpp': No such file or directory

Build finished with error(s).

 *  The terminal process failed to launch (exit code: -1). 
 *  Terminal will be reused by tasks, press any key to close it

Upvotes: 1

Views: 122

Answers (1)

SkullHeadI
SkullHeadI

Reputation: 39

As one commenter mentioned:

The first link showed 3 compilers. gcc, clang and msvc v19 latest (which means the compiler in Visual Studio 2022). You are using a msvc version from Visual Studio 2019: "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"

The answer to the question was to change the compiler path to 2022, as suggested here, thanks! C:\Program Files\Microsoft Visual Change the compiler path to Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\Hostx64\x64

Upvotes: 2

Related Questions