help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make and c++ exceptions


From: Steve Hutton
Subject: Re: make and c++ exceptions
Date: Sat, 6 Sep 2003 17:14:21 -0400
User-agent: KMail/1.5.1

On Saturday 06 September 2003 03:01 pm, Paul D. Smith wrote:
> %% Steve Hutton <address@hidden> writes:
>
>   sh> I noticed that my automake-generated makefile was reporting "FAIL"
>   sh> for make check tests that throw (and catch) C++ exceptions, even
>   sh> when they return 0.
>
>   sh> I have extracted and simplified the make-check target into a
>   sh> standalone Makefile which reproduces the behavior - that is, the
>   sh> simple test program below called "return0throw" is seen by make as
>   sh> returning 134, instead of 0.  A standalone bash script confirms
>   sh> that bash sees a return of 0.
>
>   sh> Can anyone reproduce and/or explain this?
>
> First, please always provide the version of GNU make you're using and
> the type of operating system you're using when reporting problems or
> asking for help.

Sure:
$ make --version
GNU Make version 3.79.1, by Richard Stallman and Roland McGrath.
Built for i686-pc-linux-gnu

> Second, there is no way make can be involved in this directly, because
> the entire script you have written is being passed to the shell: make is
> not involved in _ANY_ way here:

I certainly agree in theory (and that's one reason I didn't supply version 
details).  Automake actually wrote the script for me when it generated it's 
make target.  What I posted here was a minimalist test case derived from the 
script that automake created.

> the shell runs the programs, the shell
> detects the exit status, and the shell prints the exit status.  In all
> this time, make is sleeping waiting for the shell to exit.

> Finally, I don't understand why you used a "similar" script to test the
> standalone behavior rather than the _exact_ script.

The reason I did that is because when I copied the script verbatim
it didn't run in bash.  This led me to believe that shell language automake
generates is not bash compatible (e.g. make seems to treat "$$" in it's 
scripts the same way bash treats "$")

I was therefore wondering if make might use it's own shell interpreter.  You 
seem to be saying that make forwards to the shell (which one, the default 
shell of the user? Does it preprocess first to convert $$ to $?)

> Try using a shell script identical to the one make invokes (using a for
> loop, etc.), instead of somewhat different, and see if you get the same
> behavior or not.

Ok, this is about as simple an example as I can create - should only take a
few seconds for anyone to compile and make:

$ more return0.cpp return0throw.cpp Makefile
::::::::::::::
return0.cpp
::::::::::::::
int main()
{
 return 0;
}
::::::::::::::
return0throw.cpp
::::::::::::::
void throwSomething()
{
   throw("hello");
}

int main()
{
  try
  {
     throwSomething();
  }
  catch(...)
  {

  }
  return 0;
}
::::::::::::::
Makefile
::::::::::::::
all: throw nothrow

throw: return0throw
            if ./return0throw; then \
                echo "PASS: $$?"; \
            else \
                echo "FAIL: $$?"; \
            fi; \

nothrow: return0
        if ./return0; then \
           echo "PASS: $$?"; \
        else \
           echo "FAIL: $$?"; \
        fi; \

return0throw: return0throw.cpp
        g++ -o return0throw return0throw.cpp

return0: return0.cpp
        g++ -o return0 return0.cpp

clean:
        rm -rf *.o return0 return0throw

Now, run make to see it thinks return0throw returned 134:

$ make
g++ -o return0throw return0throw.cpp
if ./return0throw; then \
        echo "PASS: $?"; \
    else \
        echo "FAIL: $?"; \
    fi; \

FAIL: 134
g++ -o return0 return0.cpp
if ./return0; then \
   echo "PASS: $?"; \
else \
   echo "FAIL: $?"; \
fi; \

PASS: 0

Finally, run the bash script to see it thinks the same program returns 0:

$ more test.sh; ./test.sh
#!/bin/sh

if ./return0throw; then
   echo "PASS: $?";
else
   echo "FAIL: $?";
fi;
PASS: 0

Steve










reply via email to

[Prev in Thread] Current Thread [Next in Thread]