I am having significant trouble configuring flycheck for C++11. Right now, flycheck is flagging things like std::to_string()
. The checker I am using is just g++. What can I add in the .emacs file such that flycheck will assume C++11 by default?

- 106,671
- 19
- 240
- 328

- 4,039
- 13
- 43
- 91
2 Answers
Flycheck provides the option flycheck-gcc-language-standard
for this purpose. You should not set it globally, because that will break checking of C files, but you can set it from c++-mode-hook
with the following code in your init file:
(add-hook 'c++-mode-hook (lambda () (setq flycheck-gcc-language-standard "c++11")))
However, I would recommend against this. Instead, use Directory Variables to configure the language standard per project.
Open the root directory of your project in Dired with C-x d
, and then type M-x add-dir-local-variable RET c++-mode RET flycheck-gcc-language-standard RET "c++11"
. This will create a .dir-locals.el
file in the root directory of your project. Emacs reads this file whenever you visit a file from this directory or any subdirectory, and sets variables according to the rules in this file. Specifically, Emacs will now set the language standard for Flycheck syntax checking to C++ 11 for all C++ files in your project.
-
I tried that with directory variables and in the C++ buffer, the variable shows as *c++11*. But I still got warning as *auto type specifier is a C++11 extension*. – Enze Chi Oct 03 '15 at 04:23
-
@Enzo Chi, Works for me, probably you need to delete the file buffer and reopen the file. – Ted Feng May 24 '16 at 01:10
-
12Just in case it does not work for some people: it seems that flycheck will use clang before gcc if the former is installed. In that case the variable is flycheck-clang-language-standard. – dmg Jan 21 '17 at 09:38
-
I have nested projectile directories How to set this function recursively for all directory under tree ? – prasad Sep 11 '17 at 17:16
-
c++-mode is not an option, but I have c-c++/[]-cc-mode, and in the brackets the options {init, init-cmake, pre-init, post-init-cc, ...} how can I set up the std=c++11? – Moises Rojo Feb 13 '18 at 17:05
-
1If setting *language standard* doesn't work for you, you can always set compiler flags directly: `(setq flycheck-clang-args "-std=c++11")` – strongwillow May 16 '20 at 08:43
Very good answers already. I just want to add, that if you use clang
instead, then the variable needed to be modified is flycheck-clang-language-standard
.

- 1,222
- 10
- 25
-
1or add one line "-std=c++11" in the .clang_complete file located at the root directory of your project. – Elinx Feb 11 '18 at 03:35