jeudi 30 juin 2016

error: ‘NOEXCEPT’ does not name a type | error: expected initializer before ‘_NOEXCEPT’

I am trying to compile C++ a file on my RaspberryPi (Linux) but it is throwing an error of :

error: expected initializer before ‘_NOEXCEPT’ JSONException JSONException::MissingKey(const std::string &key) _NOEXCEPT ^ /root/libapiai_demo/libapiai/apiai/src/exceptions/JSONException.cpp:23:101: error: expected initializer before ‘_NOEXCEPT’ JSONException JSONException::TypeMismatch(const std::string &key, const std::string &expected_type) _NOEXCEPT

I even tried to replace it with throw() and _GLIBCXX_USE_NOEXCEPT but that didn't work.

On replacing it with noexcept (small) It throws an error of:

error: declaration of ‘ai::Exception::Exception(const char*) noexcept’ has >a different exception specifier Exception::Exception(const char *reason) noexcept: reason(reason) {

Is it a problem with my compiler but I am using a latest one.

My CMake txt file also has :

include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
elseif(COMPILER_SUPPORTS_CXX0X)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
        message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()

add_compile_options(-std=c++11)

For code to compile, still it throws errors.

g++ --version g++ (Raspbian 4.9.2-10) 4.9.2

Below is the 1 such file which throws the error.

Is it like 4.9.2 doesn't support noexcept. Can someone help me with this since I am stuck.

#ifndef EXCEPTION_H
#define EXCEPTION_H

#include <string>
#include <exception>

namespace ai {

class Exception: public std::exception
{
private:
    std::string reason;
public:

    Exception(const char *reason) _NOEXCEPT;

    virtual const char* what() const _NOEXCEPT override;

    virtual ~Exception() _NOEXCEPT;
};

}
#endif // EXCEPTION_H

Aucun commentaire:

Enregistrer un commentaire