How can clang avoid to analyze the builtin type/function in C/C++? - c++

/usr/lib/gcc/x86_64-redhat-linux/4.8.2/include/stdarg.h:40:9: error: unknown type name '__builtin_va_list'; did you mean '__builtin_va_list'?
typedef __builtin_va_list __gnuc_va_list;
^
note: '__builtin_va_list' declared here
When I try to use the RecursiveASTVisitor to visit the AST, I got the above problem. And at the end, the program abort with the following message.
type: Typedef of __gnuc_va_list size CItutorial5: /home/lotay/libs/clang/llvm/include/llvm/Support/Casting.h:239: typename cast_retty<X, Y *>::ret_type llvm::cast(Y *) [X = clang::ConstantArrayType, Y = const clang::Type]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Aborted (core dumped)
Really thanks for help
and I have the langoptions with following confs.
langOpts.GNUMode = 1 ;
langOpts.CXXExceptions = 1 ;
langOpts.RTTI = 1 ;
langOpts.Bool = 1 ;
langOpts.CPlusPlus = 1 ;
langOpts.WChar = 1 ;

Related

gfortran: Error: Syntax error in OPEN statement at (1) [duplicate]

This question already has an answer here:
Old fortran code and getting an OPEN statement error using GNU
(1 answer)
Closed 7 months ago.
I am compiling a code using gfortran and am getting the error:
tui:~/SCRIPTS/FORTRAN> gfortran -c pulser_ensemble_m.f
pulser_ensemble_m.f:73.18:
OPEN(UNIT=1, NAME=FOUT,ACCESS='SEQUENTIAL',TYPE='NEW')
1
Error: Syntax error in OPEN statement at (1)
The section of code is copied below::
FOUT = TEXTIN('ENTER FILTER, ENSEMBLE AVERAGE FILE','-')
OPEN(UNIT=1, NAME=FOUT,ACCESS='SEQUENTIAL',TYPE='NEW')
NAME is not a valid parameter in an OPEN statement. Here is a minimal example test.f90:
program test
character (len = *), parameter :: file_name = 'test.txt'
integer, parameter :: u=11
open (unit = u, name = file_name, status = 'new')
write (u, *) 'hello world!'
close (u)
end program test
Once compiled and run, it will give
test.f90:6:18:
6 | open (unit = u, name = file_name, status = 'new')
| 1
Error: Syntax error in OPEN statement at (1)
But if you replace name = file_name with file = file_name, the code will compile correctly and you will write the dummy text into the file.

Nim - Function type of int has to be discarded

I am new to Nim, and wrote this simple code for fun:
var x: int = 3
var y: int = 4
if true:
y = 7
else:
x = 7
proc hello(xx: int, yy: int, ): int =
return xx + yy
hello(x, y)
The code seems fine (I checked with the Nim manuals), but it gives this weird error:
c:\Users\Xilpex\Desktop\Nim_tests\testrig.nim(12, 6) Error: expression 'hello(x, y)' is of type 'int' and has to be discarded
Why am I getting this error? Is there something I can do to fix it?
You are getting an error because procs declared to return values are meant to use that value somewhere, so the compiler reminds you that you are forgetting the result of the call. If some times you want the result, and others you want to ignore it, instead of creating a temporal variable you can use the discard statement or declare the proc as {.discardable.}.
I just found out why I was getting that error... It was because the procedure returned a value, and I wasn't storing that value anywhere. Here is the working code:
var x: int = 3
var y: int = 4
if true:
y = 7
else:
x = 7
proc hello(xx: int, yy: int, ): int =
return xx + yy
var output = hello(x, y)

Fortran 90 : return error

Hello I am a new user in fortran.
I try to use a subroutine for my project. The code is quite simple and below is the code
subroutine initial_data(f, x, y, z)
implicit none
REAL :: f, x, y, z
! Adding function
#include "func_expr.h"
return
end subroutine
func_expr.h is separate file that I created because expression of f is really complicated. And I got the following error messages:
error #5082: Syntax error, found IDENTIFIER 'RETURN' when expecting one of: * ) :: , ; . (/ + - : ] /) ' ** / // > .LT. < ...
return
----^
and
error #6404: This name does not have a type, and must have an explicit type. [RETURN]
return
----^
compilation aborted for initial.f90.f (code 1)
I am not sure which part is wrong and why return has the problem of it.
Any help is really appreciated!

Expected Method Call with Array as an argument

For the following mock:
class MockUI8CBuff : public UI8CBuff_I {
public:
MOCK_METHOD2(put, unsigned(const uint8_t* start, unsigned n));
};
And the following Test Snippet
MockUI8CBuff BFO;
uint8_t arr[] = {1, 2, 3};
EXPECT_CALL(BFO, put(ElementsAreArray(arr, 3), 2))
.WillOnce(Return(1));
I Get the following Error
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h|3114 col 20| error: type 'StlContainer' (aka 'const unsigned char *') cannot be used prior to '::' because it has no members
|| typedef typename StlContainer::value_type Element;
|| ^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-matchers.h|3532 col 28| note: in instantiation of template class 'testing::internal::ElementsAreMatcherImpl<const unsigned char *>' requested here
|| return MakeMatcher(new ElementsAreMatcherImpl<Container>(
|| ^
miwt-os/coap/unittest/cbor_encoder_test.cpp|126 col 26| note: in instantiation of function template specialization 'testing::internal::ElementsAreArrayMatcher<unsigned char>::operator Matcher<const unsigned char *>' requested here
|| EXPECT_CALL(BFO, put(::testing::ElementsAreArray(arr, 3), 2))
|| ^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-spec-builders.h|1845 col 61| note: expanded from macro 'EXPECT_CALL'
|| #define EXPECT_CALL(obj, call) GMOCK_EXPECT_CALL_IMPL_(obj, call)
|| ^
/home/sporty/ws-ccs/googletest/googlemock/include/gmock/gmock-spec-builders.h|1844 col 20| note: expanded from macro 'GMOCK_EXPECT_CALL_IMPL_'
|| ((obj).gmock_##call).InternalExpectedAt(__FILE__, __LINE__, #obj, #call)
|| ^
|| 1 error generated.
miwt-os/coap/unittest/cbor_encoder.makefile|109| recipe for target 'cbor_encoder_test.o' failed
|| make: *** [cbor_encoder_test.o] Error 1
Why do I get this error? The following works:
EXPECT_CALL(BFO, put(Pointee(1), 2))
.WillOnce(Return(1));
Pointers cannot be compared to arrays. You should use the syntax like so:
EXPECT_CALL(BFO, put(_, _))
.With(Args<0,1>(ElementsAre(1, 2, 3))); // ElementsAreArray can also be used

Unclassifiable statement and other errors in an IF in Fortran

I have the code:
if i < n then
x = topsep(1)
y = topsep(2)
realvor(n,1) = x + dx
realvor(n,2) = x + dy
imvor(n,1) = (realvor(n,1)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2)
imvor(n,2) = (realvor(n,2)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2)
tf = .TRUE.
else
x = botsep(1)
y = botsep(2)
realvor(n,1) = x + dx
realvor(n,2) = y - dy
imvor(n,1) = (realvor(n,1)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2)
imvor(n,2) = (realvor(n,2)*(a**2))/((realvor(n,1))**2+(realvor(n,2))**2)
tf = .FALSE.
endif
Both i and n are defined as integers and I am inside a do loop for n = 1,100. This throws up the following errors:
Error: Unclassifiable statement at (1) at the 'if i< n then'
Error: Unexpected ELSE statement at (1) at the 'else'
Error: Expecting END DO statement at (1) at the 'endif'
I can't see where these errors are coming from, no matter how I write the if statement (.NE. etc.) it seems to throw up the same things.
You forgot the parenthesis! According to the Fortran standard (2008, ch. 8.1.7.4), the if statement should read
if ( i < n ) then