标签: gcc4.7

在G ++ 4.7中的内联函数中定义时未找到Lambda

我在头文件中定义了以下函数(该库是目标只是头文件的一部分):

typedef bool (*FieldComparer)(const std::string&, const std::string&);

inline FieldComparer
GetComparer(const std::string& query, string& separator)
{
    if (query.find('=') != std::string::npos) {
        separator = "=";
        return [](const string& s1, const string& s2) { return s1 == s2; };
    }
    else if (query.find('^') != string::npos) {
        separator = "^";
        return [](const string& s1, const string& s2) { return boost::starts_with(s1, s2); };
    }
    else if (query.find('*') != string::npos) {
        separator = "*";
        return [](const string& s1, const string& s2) { return boost::contains(s1, s2); }; …
Run Code Online (Sandbox Code Playgroud)

c++ c++11 gcc4.7

31
推荐指数
1
解决办法
1165
查看次数

c ++:按值复制到函数params在vs2012中生成两个对象

这里的代码在g ++ 4.7和vs2012(cl17)中产生不同的输出.

#include <iostream>

using namespace std;

class A
{
public:
    A() { cout << "1" << endl; }
    ~A() { cout << "2" << endl; }
};

class B : public A
{
public:
    B() { cout << "3" << endl; }
    ~B() { cout << "4" << endl; }
};

void func(A a) {}

int main()
{
    B b;
    func(b);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

GCC输出是13242,而cl输出132242.

为什么cl编译器A在堆栈上复制时会产生第二个对象,出于什么目的?

c++ gcc visual-c++ gcc4.7 visual-studio-2012

23
推荐指数
2
解决办法
331
查看次数

map :: emplace()具有自定义值类型

我在使用时遇到了麻烦map::emplace().任何人都可以帮我找出正确的语法吗?我正在尝试做与此示例中相同的操作.这是我的版本:

#include <map>
using namespace std;

class Foo
{
  // private members

  public:
    Foo(int, char, char) /* :init(), members() */ {  }

    // no default ctor, copy ctor, move ctor, or assignment
    Foo() = delete;
    Foo(const Foo&) = delete;
    Foo(Foo &&) = delete;
    Foo & operator=(const Foo &) = delete;
    Foo & operator=(Foo &&) = delete;
};


int main()
{
  map<int, Foo> mymap;
  mymap.emplace(5, 5, 'a', 'b');

  return 0;
}
Run Code Online (Sandbox Code Playgroud)

根据GCC 4.7(带有-std=c++11标志),我emplace在线上错了. …

c++ gcc c++11 gcc4.7

20
推荐指数
1
解决办法
9053
查看次数

GCC bug还是UB?这段代码应该编译吗?

下面的代码用clang编译好,但不用GCC编译(试过4.1.2,4.5.4和4.7.2):

template <typename T>
struct A
{
    struct B { };
};

template <typename T>
bool operator==(typename A<T>::B const& b, T const&  t);

enum { BAR };

template <typename T>
bool test()
{
    return 0 == BAR;
}
Run Code Online (Sandbox Code Playgroud)

GCC 4.7.2的错误消息是:

a.cpp: In instantiation of ‘struct A<<anonymous enum> >’:
a.cpp:12:6:   required by substitution of ‘template<class T> bool operator==(const typename A<T>::B&, const T&) [with T = <anonymous enum>]’
a.cpp:19:17:   required from here
a.cpp:6:12: error: ‘<anonymous enum>’ is/uses anonymous type
a.cpp:6:12: …
Run Code Online (Sandbox Code Playgroud)

c++ gcc gcc4.7

16
推荐指数
1
解决办法
641
查看次数

(优化?)关于GCC std :: thread的Bug

在测试某些功能的同时std::thread,一位朋友遇到了GCC的问题,我们认为值得问一下这是否是GCC错误或者这个代码可能有问题(代码打印(例如)"7 8 9 10 1 2 3" ,但我们希望打印[1,10]中的每个整数:

#include <algorithm>
#include <iostream>
#include <iterator>
#include <thread>

int main() {
    int arr[10];
    std::iota(std::begin(arr), std::end(arr), 1);
    using itr_t = decltype(std::begin(arr));

    // the function that will display each element
    auto f = [] (itr_t first, itr_t last) {
        while (first != last) std::cout<<*(first++)<<' ';};

    // we have 3 threads so we need to figure out the ranges for each thread to show
    int increment = std::distance(std::begin(arr), std::end(arr)) / 3;
    auto first …
Run Code Online (Sandbox Code Playgroud)

multithreading clang c++11 gcc4.7

14
推荐指数
1
解决办法
555
查看次数

g ++ 4.7将运算符""评估为宏扩展的兄弟

我正在将一些代码移到GCC 4.7(从4.6)并遇到一些编译错误,并发现GCC 4.7移植指南中记录的问题:

用户定义的文字和空格

ISO C11模式下的C++编译器std={c++11,c++0x,gnu++11,gnu++0x} 支持用户定义的文字,这些文字与某些有效的ISO C++ 03代码不兼容.

特别是,现在需要在字符串文字之后和可能是有效的用户定义文字之前的空格.获取有效的ISO C++ 03代码

const char *p = "foobar"__TIME__;
Run Code Online (Sandbox Code Playgroud)

在C++ 03中,TIME宏扩展为某个字符串文字,并与另一个字符串连接.在C++ 11 __TIME__中没有扩展,而是operator "" __TIME__被查找,导致以下诊断:

error: unable to find string literal operator  ‘operator"" __TIME__’
Run Code Online (Sandbox Code Playgroud)

这适用于某些宏后面没有空格的任何字符串文字.要修复,只需在字符串文字和宏名称之间添加一些空格.

虽然我可以修复错误,但我想知道为什么我必须这样做.__TIME__是一个宏,因此"something"__TIME__"something""15:52:03"在预处理阶段变为(或类似),因此编译器永远不会有机会将其视为operator "".

这种行为是标准认可还是错误?

c++ compilation user-defined-literals gcc4.7

13
推荐指数
1
解决办法
976
查看次数

gcc c ++ 11限制用户定义的常量和模板参数包

我一直在gcc 4.7.2中玩用户定义的常量,并遇到了一些我不太了解的大小限制因素.

我们的想法是为定点十进制类型定义一个constexpr运算符"".我想避免使用variadic模板从double进行转换,而是在编译时解析尾数和指数.尾数解析证明有点棘手.

当我启用下面代码底部的3条禁用行中的任何一行时,gcc会陷入无限循环并挂起.我注意到浮点文字的最大大小和可变参数模板的显式实例化,但整数文字的大小略大.

我用了命令:g ++ -std = c ++ 11 -Wall -g -o literal_value literal_value.cpp

使用-ftemplate-depth-128没有区别.

#include <iostream>
#include <cstdint>

typedef std::uint64_t value_type;

template<value_type Temp, char... List> struct literal_parser;

template<value_type Temp, char Head, char... List>
struct literal_parser<Temp, Head, List...>
{
    static const value_type value = Head == '.' ?
        literal_parser<Temp, List...>::value :
        literal_parser<Temp * 10 + Head - '0', List...>::value;
};

template<value_type Temp, char Last>
struct literal_parser<Temp, Last>
{
    static const value_type value = Last == '.' ?
        Temp …
Run Code Online (Sandbox Code Playgroud)

c++ c++11 gcc4.7

13
推荐指数
1
解决办法
892
查看次数

如何禁用缩小转换警告?

我使用-Wall并更新到新的gcc我有很多warning: narrowing conversion.我想禁用它们,但保持所有其他警告不受影响(理想情况下).

narrowinghttp://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html中找不到任何内容

如何禁用缩小转换警告?有可能吗?

PS

  1. 我需要禁用警告,而不是在源代码中修复它们.

  2. 盲目-Wno-conversion没有帮助.

c++ gcc warnings compiler-options gcc4.7

13
推荐指数
1
解决办法
2万
查看次数

gcc -march选项的默认值是什么?

gcc信息文件在x86-64特定标志的部分中说明,其中包括:

      There is no `-march=generic' option because `-march'
      indicates the instruction set the compiler can use, and there
      is no generic instruction set applicable to all processors.
      In contrast, `-mtune' indicates the processor (or, in this
      case, collection of processors) for which the code is
      optimized.
Run Code Online (Sandbox Code Playgroud)

我的问题是,当没有给出-march选项时,gcc编译的指令(子)集是什么?在webosphere中有很多关于-march和-mtune的相关信息,但我找不到哪个能回答这个简单的问题.它不能是march = native,否则就不可能编译通用分发内核和二进制包.

gcc gcc4 gcc4.7

13
推荐指数
1
解决办法
4861
查看次数

什么是windows的gcc端口中的thread_posixs和thread_win32之间的区别?

我想下载最新版本的gcc 4.7.2Windows编译器.
当我到这个页面在这里我本来是要看到一个下载链接,我面临着两大类:

  1. 线程,POSIX
  2. 线程-win32的

这两者之间有什么区别?
它们只是线程实现吗?我的意思是它们只是在实现方式上有所不同,因此结束结果(类,如何使用它们等)保持不变?
或者他们是否强加了特定的编码风格?

c++ windows multithreading gcc4.7

11
推荐指数
1
解决办法
9685
查看次数