How can I handle warnings generated by Boost.Spirit?

I installed boost recently, and I experimented with the Spirit library. I made a simple example that analyzes a comma-separated list of numbers and adds them together. The program compiled, but my compiler (VS 2013) issued multiple warnings. Look at the source:

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>
#include <string>

#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#include <iostream>
#include <string>

namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;
namespace phoenix = boost::phoenix;

using qi::double_;
using qi::_1;
using ascii::space;
using phoenix::ref;

template <typename Iterator>
bool adder(Iterator first, Iterator last, double& n)
{
    bool r = qi::phrase_parse(first, last,

        //  Begin grammar
        (
            double_[ref(n) = _1] >> *(',' >> double_[ref(n) += _1])
        )
        ,
        //  End grammar

        space);

    if (first != last) // fail if we did not get a full match
        return false;
    return r;
}

int main()
{
    std::string str;
    std::getline(std::cin, str);
    double result;
    if (!adder(str.begin(), str.end(), result))
    {
        std::cout << "Invalid syntax." << std::endl;
    }
    std::cout << "The result is " << result << std::endl;
    return 0;
}

This triggered 309 warning lines! They all looked something like this:

c:\boost\boost/spirit/home/support/terminal.hpp(264) : warning C4348: 'boost::spirit::terminal<boost::spirit::tag::lit>::result_helper' : redefinition of default parameter : parameter 3
        c:\boost\boost/spirit/home/support/terminal.hpp(270) : see declaration of 'boost::spirit::terminal<boost::spirit::tag::lit>::result_helper'
        c:\boost\boost/spirit/home/support/common_terminals.hpp(142) : see reference to class template instantiation 'boost::spirit::terminal<boost::spirit::tag::lit>' being compiled

The program compiled and did what I thought it would do, but I wonder how to manage all these warnings without silencing the useful ones. Is there a way to disable warnings that arise from boost, but keep warnings generated by my code? Spirit is a pretty popular library, so I know there is a way to deal with it.

+4
1

V++ Boost :

#pragma warning(push)
#pragma warning(disable : 4348)
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix_core.hpp>
#include <boost/spirit/include/phoenix_operator.hpp>
#pragma warning(pop)

#include <iostream>
#include <string>

// ...

disable, (docs).

include "" , . GCC Clang, , -isystem, -I (docs).

+6

Source: https://habr.com/ru/post/1623666/


All Articles