AppCode falsely reporting errors in C++ editor - c++

I'm trying out AppCode and CLion for developing an C++ app on macOS. CLion seems to work well, but it's not obvious how to build a Cocoa/AppKit app, or an iOS app. I downloaded a trial of AppCode, thinking it would have the same C++ engine, but it chokes on a lot of code.
A couple examples:
It thinks there is no conversion from char * to std::string.
It can't see the overloads in the popular fmt library.
CLion parses this stuff. Maybe I should work on getting that to build a macOS app. Is there a way to get AppCode to parse this properly and not incorrectly report errors with red underlines and popups? It compiles and runs fine. It's the editor having problems and showing "errors" in the code.
#include <string>
#include "fmt/format.h"
int main(int argc, const char * argv[]) {
int x = 10;
int y = 25;
std::string name = "Godzilla";
fmt::print("x + y = {}, name = {}", x+y, name);
return 0;
}
Screenshot from AppCode.
The errors reported incorrectly by the editor are:
Types 'std::string' and 'const char[9]' are not compatible.
Parameter type mismatch: Incompatible pointer types 'FILE *' and 'const char[22]'

Related

Defining a char array in c++

Having such a super simple char array definition:
const int g_msgbuf_size = 200;
char g_msgbuf[g_msgbuf_size];
giving me an totally unreasonable error:
error C2057: expected constant expression
on the second line while compiling in MSVC 2019.
When i try the code on any other c++ compiler like https://www.onlinegdb.com/online_c++_compiler or http://cpp.sh/ everything goes well - I get no errors as expected.
Why does the MSVC 2019 makes me problems?

Is there a C++ compiler flag in Visual Studio for int assumed?

I am trying to compile some old C++ in Visual Studio 2008 that compiles in Visual C++ 6. I am trying to deal with the errors through configuration changes and compiler instructions instead of changing the code.
In a lot of places in the code, there are variables and functions declared without a type. The compiler gives an error like "error C4430: missing type specifier - int assumed. Note: C++ does not support default-int".
For example:
class DLL WebPage
{
private:
char *ip_;
char *port_;
char *page_;
public:
WebPage();
~WebPage();
get(char *ip,char *port,char *page); //<---This is the trouble maker
char *ip(void);
char *port(void);
char *page(void);
};
Any way to get this to compile in a newer IDE?

Compiler error for std::string in c++ builder XE3 project

I am working on a service application in c++ builder XE3.
I am getting compiler error for std::string if I add this line:
string a = string("abcd") + "xyz";
Error output is as follows:
[bcc32 Error] string(141): E2285 Could not find a match for 'move<_Ty>(string)'
Full parser context
string(140): decision to instantiate: string std::string + <char,char_traits<char>,allocator<char> >(string &&,const char *)
--- Resetting parser context for instantiation...
svcmain.cpp(21): #include C:\Program Files\Embarcadero\RAD Studio\10.0\include\boost_1_39\boost\tr1\tr1\string
string(20): #include c:\program files\embarcadero\rad studio\10.0\include\../include/dinkumware/string
string(7): namespace std
string(140): parsing: string std::string + <char,char_traits<char>,allocator<char> >(string &&,const char *)
I tried to add #include <utility> just above #include <string> but still getting same error.
Instead, if I split the line into two as follows, it compiles without errors.
string a = string("abcd");
a += "xyz";
OR
string b = string("abcd");
string a = b + "xyz";
Its not practical to use this workaround as I have to use existing code which is getting large no of errors. Same code works without errors in other XE3 project.
Any ideas how to fix this error?
I found the fix in the other project. Setting the "backward compatibility" option to false fixed the error.
You can find the checkbox in - Project options -> C++ compiler -> Compatibility -> General.
This was initially set to true.

Why are std::stoi and std::array not compiling with g++ c++11?

I've been learning C++ and using the Terminal for the last couple of months. My code was compiling and running fine using g++ and C++11, but in the last couple of days it started giving errors and I have had problems compiling since. The only programs I can compile and run depend on older C++ standards.
The errors I first got related to #include < array > in the header file. Not sure why this happened, but I got around it by using boost/array instead. Another error I can't solve is with std::stoi. Both array and stoi should be in the C++11 standard library. I made the following simple code to demonstrate what's going on:
//
// stoi_test.cpp
//
// Created by ecg
//
#include <iostream>
#include <string> // stoi should be in here
int main() {
std::string test = "12345";
int myint = std::stoi(test); // using stoi, specifying in standard library
std::cout << myint << '\n'; // printing the integer
return(0);
}
Try to compile using ecg$ g++ -o stoi_trial stoi_trial.cpp -std=c++11
array.cpp:13:22: error: no member named 'stoi' in namespace 'std'; did you mean
'atoi'?
int myint = std::stoi(test);
~~~~~^~~~
atoi
/usr/include/stdlib.h:149:6: note: 'atoi' declared here
int atoi(const char *);
^
array.cpp:13:27: error: no viable conversion from 'std::string' (aka
'basic_string') to 'const char *'
int myint = std::stoi(test);
^~~~
/usr/include/stdlib.h:149:23: note: passing argument to parameter here
int atoi(const char *);
^
2 errors generated.
I also get these errors at compilation when using gcc or clang++ and with -std=gnu++11 (I guess they all depend on the same file structure). I also get the same error whether I specify std:: in the code, or if I specify using namespace std;
I worry that these issues arose because of the September Command Line Tools update via Xcode or because I installed boost and this somehow messed up my C++11 libraries. Hopefully there is a simple solution.
My system:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-> dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
Thanks for any insight you can offer.
clang has a weird stdlib, you need to add the following flag when you compile
-stdlib=libc++
your snippet works on my mac with
g++ -std=gnu++11 -stdlib=libc++ test.cpp -o test
This answer describes the problem

fuse (Filesystem in Userspace) error: expected primary-expression before ‘.’ token

When I compile this helloworld example, I get the following error repeated 4 times:
error: expected primary-expression before ‘.’ token
Here is the code:
static struct fuse_operations hello_oper = {
.getattr = hello_getattr,
.readdir = hello_readdir,
.open = hello_open,
.read = hello_read,
};
int main(int argc, char *argv[])
{
return fuse_main(argc, argv, &hello_oper);
}
Your compiler is too old. It needs to support C99. Pass in -std=c99 if the compiler is current enough
That syntax is using a new feature of the C99 language standard called designated initializers. That feature is not part of the more common C89 standard (aka ANSI C), so a C89 compiler will give you syntax errors when you try to compile code that uses it.
To fix it, tell your compiler to use its C99 mode if it has one. For example, if you're using GCC, you should pass the -std=c99 compiler option. If your compiler doesn't support C99 at all, you'll have to either switch to a compiler that does, or refactor the code to avoid using C99 features.
Actually, gcc support newer dialects of C (or of C++). Try passing it gcc -std=c99 -Wall
Ran into a similar error, although I was unable to overcome it by adding "#define FUSE_USE_VERSION ..." as mentioned in one of the comments above.
To overcome the error, I wrote a wrapper around the fuse_operations as follows:
struct my_operations: public fuse_operations {
my_operations()
{
read = my_read;
open = my_open;
}
} operations;
main(int argc, char* argv[])
{
return fuse_main(argc, argv, &operations, NULL);
}